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);
}
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);
}
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();
}
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();
}
}
}
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);
}
}
Aggregations