List of usage examples for android.content Intent addCategory
public @NonNull Intent addCategory(String category)
From source file:com.dm.material.dashboard.candybar.helpers.RequestHelper.java
@NonNull public static List<Request> loadMissingApps(@NonNull Context context) { List<Request> requests = new ArrayList<>(); Database database = new Database(context); String activities = RequestHelper.loadAppFilter(context); PackageManager packageManager = context.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> installedApps = packageManager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); CandyBarMainActivity.sInstalledAppsCount = installedApps.size(); try {//from www. j a v a 2s . co m Collections.sort(installedApps, new ResolveInfo.DisplayNameComparator(packageManager)); } catch (Exception ignored) { } for (ResolveInfo app : installedApps) { String packageName = app.activityInfo.packageName; String activity = packageName + "/" + app.activityInfo.name; if (!activities.contains(activity)) { String name = LocaleHelper.getOtherAppLocaleName(context, new Locale("en-US"), packageName); if (name == null) name = app.activityInfo.loadLabel(packageManager).toString(); boolean requested = database.isRequested(activity); requests.add(new Request(name, app.activityInfo.packageName, activity, requested)); } } return requests; }
From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java
@Nullable private static String buildActivityList(Context context, File folder) { try {/*from www. j a va 2s . co m*/ File fileDir = new File(folder.toString() + "/" + "activity_list.xml"); Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileDir), "UTF8")); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> appList = context.getPackageManager().queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); try { Collections.sort(appList, new ResolveInfo.DisplayNameComparator(context.getPackageManager())); } catch (Exception ignored) { } boolean first = true; for (ResolveInfo app : appList) { if (first) { first = false; out.append("<!-- ACTIVITY LIST -->"); out.append("\n\n\n"); } String name = app.activityInfo.loadLabel(context.getPackageManager()).toString(); String activity = app.activityInfo.packageName + "/" + app.activityInfo.name; out.append("<!-- ").append(name).append(" -->"); out.append("\n").append(activity); out.append("\n\n"); } out.flush(); out.close(); return fileDir.toString(); } catch (Exception | OutOfMemoryError e) { Log.d(Tag.LOG_TAG, Log.getStackTraceString(e)); } return null; }
From source file:com.nhn.android.archetype.base.AABaseApplicationOrg.java
public static void applicationAllKill() { final ActivityManager am = (ActivityManager) _internalInstance.getSystemService(Activity.ACTIVITY_SERVICE); // stop running service inside current process. List<RunningServiceInfo> serviceList = am.getRunningServices(100); for (RunningServiceInfo service : serviceList) { if (service.pid == android.os.Process.myPid()) { Intent stop = new Intent(); stop.setComponent(service.service); _internalInstance.stopService(stop); }/*from w w w. j av a2 s. com*/ } // move current task to background. Intent launchHome = new Intent(Intent.ACTION_MAIN); launchHome.addCategory(Intent.CATEGORY_DEFAULT); launchHome.addCategory(Intent.CATEGORY_HOME); _internalInstance.startActivity(launchHome); // post delay runnable(waiting for home application launching) new Handler().postDelayed(new Runnable() { public void run() { am.killBackgroundProcesses(_internalInstance.getPackageName()); } }, 2000); }
From source file:com.adguard.android.commons.BrowserUtils.java
public static void startBrowser(Context context, ComponentName component) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(component);/*from ww w .ja v a 2 s .co m*/ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
From source file:com.adguard.android.commons.BrowserUtils.java
private static ComponentName getSamsungBrowser(Context context) { Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> installedPackages = context.getPackageManager().queryIntentActivities(mainIntent, 0); ArrayList<ActivityInfo> samsungActivities = new ArrayList<>(); for (ResolveInfo installedPackage : installedPackages) { if (installedPackage.activityInfo.packageName.startsWith(SAMSUNG_BROWSER_PACKAGE)) { samsungActivities.add(installedPackage.activityInfo); }//from ww w. ja v a 2s . c o m } if (CollectionUtils.isNotEmpty(samsungActivities)) { Collections.sort(samsungActivities, new Comparator<ActivityInfo>() { @Override public int compare(ActivityInfo lhs, ActivityInfo rhs) { return lhs.packageName.compareTo(rhs.packageName); } }); ActivityInfo activityInfo = samsungActivities.get(0); return new ComponentName(activityInfo.packageName, activityInfo.name); } return null; }
From source file:com.phonemetra.account.util.AccountUtils.java
private static Intent getWifiSetupIntent(Context context) { Intent intent = new Intent(); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setComponent(new ComponentName(Account.WIFI_COMPONENT_PKG, Account.WIFI_COMPONENT_CLASS)); intent.putExtra(Account.EXTRA_FIRST_RUN, true); intent.putExtra(Account.EXTRA_ALLOW_SKIP, false); intent.putExtra(Account.EXTRA_SHOW_BUTTON_BAR, true); intent.putExtra(Account.EXTRA_ONLY_ACCESS_POINTS, true); intent.putExtra(Account.EXTRA_AUTO_FINISH, true); return intent; }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java
public static Intent getLaunchIntent(Context context, DbObj obj) { JSONObject content = obj.getJson();//from w ww. j a v a2 s . c o m if (content.has(ANDROID_PACKAGE_NAME)) { Uri appFeed = obj.getContainingFeed().getUri(); String action = content.optString(ANDROID_ACTION); String pkgName = content.optString(ANDROID_PACKAGE_NAME); String className = content.optString(ANDROID_CLASS_NAME); Intent launch = new Intent(action); launch.setClassName(pkgName, className); launch.addCategory(Intent.CATEGORY_LAUNCHER); // TODO: feed for related objs, not parent feed launch.putExtra(AppState.EXTRA_FEED_URI, appFeed); launch.putExtra(AppState.EXTRA_OBJ_HASH, obj.getHash()); // TODO: Remove launch.putExtra("obj", content.toString()); List<ResolveInfo> resolved = context.getPackageManager().queryIntentActivities(launch, 0); if (resolved.size() > 0) { return launch; } Intent market = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + pkgName)); return market; } else if (content.has(WEB_URL)) { Intent app = new Intent(Intent.ACTION_VIEW, Uri.parse(content.optString(WEB_URL))); app.setClass(context, AppFinderActivity.class); app.putExtra(Musubi.EXTRA_FEED_URI, Feed.uriForName(obj.getFeedName())); return app; } return null; }
From source file:com.brewcrewfoo.performance.activities.PCSettings.java
public static boolean isDownloadManagerAvailable(Context context) { try {// w ww . ja v a2s . co m if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { return false; } Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList"); List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; } catch (Exception e) { return false; } }
From source file:com.codyy.rx.permissions.RxPermissions.java
/** * ???/*from www .j ava 2s . c o m*/ * * @param context context * @param packageName ?? */ public static void openPermissionSettings(@NonNull Context context, @NonNull String packageName) { Intent intent = new Intent(); intent.setAction("miui.intent.action.APP_PERM_EDITOR");//??MIUI??? intent.addCategory(Intent.CATEGORY_DEFAULT); intent.putExtra("extra_pkgname", packageName); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); } else { Uri packageURI = Uri.parse("package:" + packageName); intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS", packageURI);//??? if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); } else { Toast.makeText(context, "???", Toast.LENGTH_SHORT).show(); } } }
From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java
private static void setCommonOpenOptions(Intent intent, String mimeType) { intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(mimeType);/*from w ww . jav a 2 s.c om*/ }