Search in sources :

Example 11 with PackageManager

use of android.content.pm.PackageManager in project cw-advandroid by commonsguy.

the class Launchalot method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    PackageManager pm = getPackageManager();
    Intent main = new Intent(Intent.ACTION_MAIN, null);
    main.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> launchables = pm.queryIntentActivities(main, 0);
    Collections.sort(launchables, new ResolveInfo.DisplayNameComparator(pm));
    adapter = new AppAdapter(pm, launchables);
    setListAdapter(adapter);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent)

Example 12 with PackageManager

use of android.content.pm.PackageManager in project cw-omnibus by commonsguy.

the class MainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PackageManager pm = getPackageManager();
    Intent main = new Intent(Intent.ACTION_MAIN, null);
    main.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> launchables = pm.queryIntentActivities(main, 0);
    List<ResolveInfo> filtered = new ArrayList<>();
    for (ResolveInfo launchable : launchables) {
        int launchMode = launchable.activityInfo.launchMode;
        if (launchMode != ActivityInfo.LAUNCH_SINGLE_INSTANCE && launchMode != ActivityInfo.LAUNCH_SINGLE_TASK) {
            filtered.add(launchable);
        }
    }
    Collections.sort(filtered, new ResolveInfo.DisplayNameComparator(pm));
    adapter = new AppAdapter(pm, filtered);
    setListAdapter(adapter);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 13 with PackageManager

use of android.content.pm.PackageManager in project cw-omnibus by commonsguy.

the class ResolveActivityDemoActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PackageManager mgr = getPackageManager();
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://commonsware.com"));
    ResolveInfo ri = mgr.resolveActivity(i, PackageManager.MATCH_DEFAULT_ONLY);
    Toast.makeText(this, ri.loadLabel(mgr), Toast.LENGTH_LONG).show();
    startActivity(i);
    finish();
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent)

Example 14 with PackageManager

use of android.content.pm.PackageManager in project GeekNews by codeestX.

the class MainActivity method initEventAndData.

@Override
protected void initEventAndData() {
    setToolBar(mToolbar, "知乎日报");
    mZhihuFragment = new ZhihuMainFragment();
    mGankFragment = new GankMainFragment();
    mWechatFragment = new WechatMainFragment();
    mGoldFragment = new GoldMainFragment();
    mVtexFragment = new VtexMainFragment();
    mLikeFragment = new LikeFragment();
    mSettingFragment = new SettingFragment();
    mAboutFragment = new AboutFragment();
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close);
    mDrawerToggle.syncState();
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    mLastMenuItem = mNavigationView.getMenu().findItem(R.id.drawer_zhihu);
    loadMultipleRootFragment(R.id.fl_main_content, 0, mZhihuFragment, mWechatFragment, mGankFragment, mGoldFragment, mVtexFragment, mLikeFragment, mSettingFragment, mAboutFragment);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch(menuItem.getItemId()) {
                case R.id.drawer_zhihu:
                    showFragment = Constants.TYPE_ZHIHU;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_gank:
                    showFragment = Constants.TYPE_GANK;
                    mSearchMenuItem.setVisible(true);
                    break;
                case R.id.drawer_wechat:
                    showFragment = Constants.TYPE_WECHAT;
                    mSearchMenuItem.setVisible(true);
                    break;
                case R.id.drawer_gold:
                    showFragment = Constants.TYPE_GOLD;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_vtex:
                    showFragment = Constants.TYPE_VTEX;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_setting:
                    showFragment = Constants.TYPE_SETTING;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_like:
                    showFragment = Constants.TYPE_LIKE;
                    mSearchMenuItem.setVisible(false);
                    break;
                case R.id.drawer_about:
                    showFragment = Constants.TYPE_ABOUT;
                    mSearchMenuItem.setVisible(false);
                    break;
            }
            if (mLastMenuItem != null) {
                mLastMenuItem.setChecked(false);
            }
            mLastMenuItem = menuItem;
            SharedPreferenceUtil.setCurrentItem(showFragment);
            menuItem.setChecked(true);
            mToolbar.setTitle(menuItem.getTitle());
            mDrawerLayout.closeDrawers();
            showHideFragment(getTargetFragment(showFragment), getTargetFragment(hideFragment));
            hideFragment = showFragment;
            return true;
        }
    });
    mSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (showFragment == Constants.TYPE_GANK) {
                mGankFragment.doSearch(query);
            } else if (showFragment == Constants.TYPE_WECHAT) {
                RxBus.getDefault().post(new SearchEvent(query, Constants.TYPE_WECHAT));
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    if (!SharedPreferenceUtil.getVersionPoint() && SystemUtil.isWifiConnected()) {
        SharedPreferenceUtil.setVersionPoint(true);
        try {
            PackageManager pm = getPackageManager();
            PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
            String versionName = pi.versionName;
            mPresenter.checkVersion(versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
Also used : GankMainFragment(com.codeest.geeknews.ui.gank.fragment.GankMainFragment) AboutFragment(com.codeest.geeknews.ui.main.fragment.AboutFragment) SettingFragment(com.codeest.geeknews.ui.main.fragment.SettingFragment) NavigationView(android.support.design.widget.NavigationView) PackageInfo(android.content.pm.PackageInfo) WechatMainFragment(com.codeest.geeknews.ui.wechat.fragment.WechatMainFragment) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) VtexMainFragment(com.codeest.geeknews.ui.vtex.fragment.VtexMainFragment) MenuItem(android.view.MenuItem) SearchEvent(com.codeest.geeknews.model.event.SearchEvent) PackageManager(android.content.pm.PackageManager) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) GoldMainFragment(com.codeest.geeknews.ui.gold.fragment.GoldMainFragment) ZhihuMainFragment(com.codeest.geeknews.ui.zhihu.fragment.ZhihuMainFragment) LikeFragment(com.codeest.geeknews.ui.main.fragment.LikeFragment)

Example 15 with PackageManager

use of android.content.pm.PackageManager in project cw-omnibus by commonsguy.

the class StopReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    Intent i = new Intent(context.getString(R.string.service_action)).setPackage(context.getPackageName());
    PackageManager mgr = context.getPackageManager();
    for (ResolveInfo ri : mgr.queryIntentServices(i, 0)) {
        ComponentName cn = new ComponentName(ri.serviceInfo.applicationInfo.packageName, ri.serviceInfo.name);
        Intent stop = new Intent().setComponent(cn);
        context.stopService(stop);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Aggregations

PackageManager (android.content.pm.PackageManager)1429 Intent (android.content.Intent)483 ResolveInfo (android.content.pm.ResolveInfo)449 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)345 ApplicationInfo (android.content.pm.ApplicationInfo)249 PackageInfo (android.content.pm.PackageInfo)248 ComponentName (android.content.ComponentName)239 ArrayList (java.util.ArrayList)156 ActivityInfo (android.content.pm.ActivityInfo)135 IOException (java.io.IOException)126 RemoteException (android.os.RemoteException)105 IPackageManager (android.content.pm.IPackageManager)93 Drawable (android.graphics.drawable.Drawable)93 Resources (android.content.res.Resources)90 PendingIntent (android.app.PendingIntent)71 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)63 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)53 ServiceInfo (android.content.pm.ServiceInfo)46