List of usage examples for android.content.pm PackageManager queryIntentActivities
public abstract List<ResolveInfo> queryIntentActivities(Intent intent, @ResolveInfoFlags int flags);
From source file:uk.co.ashtonbrsc.intentexplode.Explode.java
private Spanned getIntentDetailsString() { // TODO make sure this has all // the details StringBuilder stringBuilder = new StringBuilder(); // k3b so intent can be reloaded using // Intent.parseUri("Intent:....", Intent.URI_INTENT_SCHEME) stringBuilder.append(getUri(editableIntent)).append(NEWLINE); // support for onActivityResult if (this.lastResultCode != null) { stringBuilder.append(getResources().getString(R.string.last_result)) .append(this.lastResultCode.toString()); if (this.lastResultIntent != null) { stringBuilder.append(getResources().getString(R.string.data)).append(lastResultIntent); }//from ww w .j a va 2 s . c o m stringBuilder.append(NEWLINE); } stringBuilder.append(NEWLINE).append(getResources().getString(R.string.action_bold)) .append(editableIntent.getAction()).append(NEWLINE); stringBuilder.append(getResources().getString(R.string.data_bold)).append(editableIntent.getData()) .append(NEWLINE); stringBuilder.append(getResources().getString(R.string.type_bold)).append(editableIntent.getType()) .append(NEWLINE); Set<String> categories = editableIntent.getCategories(); if (categories != null) { stringBuilder.append(getResources().getString(R.string.categories_title_bold)); for (String category : categories) { stringBuilder.append(category).append(NEWLINE); } } stringBuilder.append(getResources().getString(R.string.flags_title_bold)); ArrayList<String> flagsStrings = getFlags(); if (!flagsStrings.isEmpty()) { for (String thisFlagString : flagsStrings) { stringBuilder.append(thisFlagString).append(NEWLINE); } } else { stringBuilder.append(getResources().getString(R.string.none)).append(NEWLINE); } try { Bundle intentBundle = editableIntent.getExtras(); if (intentBundle != null) { Set<String> keySet = intentBundle.keySet(); stringBuilder.append(getResources().getString(R.string.extras_title_bold)); int count = 0; for (String key : keySet) { count++; Object thisObject = intentBundle.get(key); stringBuilder.append(getResources().getQuantityString(R.plurals.extra_count, count, count)); String thisClass = thisObject.getClass().getName(); if (thisClass != null) { stringBuilder.append(getResources().getString(R.string.class_text)).append(thisClass) .append(NEWLINE); } stringBuilder.append(getResources().getString(R.string.key)).append(key).append(NEWLINE); if (thisObject instanceof String || thisObject instanceof Long || thisObject instanceof Integer || thisObject instanceof Boolean || thisObject instanceof Uri) { stringBuilder.append(getResources().getString(R.string.value)).append(thisObject.toString()) .append(NEWLINE); } else if (thisObject instanceof ArrayList) { stringBuilder.append(getResources().getString(R.string.values_break)); ArrayList thisArrayList = (ArrayList) thisObject; for (Object thisArrayListObject : thisArrayList) { stringBuilder.append(thisArrayListObject.toString()).append(NEWLINE); } } } } } catch (Exception e) { stringBuilder.append(getResources().getString(R.string.bundle_title_bold_uppercase)); stringBuilder.append(getResources().getString(R.string.error_extracting_extras_red)); e.printStackTrace(); } PackageManager pm = getPackageManager(); List<ResolveInfo> resolveInfo = pm.queryIntentActivities(editableIntent, 0); // Remove Intent Intercept from matching activities int numberOfMatchingActivities = resolveInfo.size() - 1; if (numberOfMatchingActivities < 1) { stringBuilder.append(getResources().getString(R.string.no_activities_match_intent_title_bold)); } else { stringBuilder.append(getResources().getQuantityString(R.plurals.activites_match_intent_title_bold, numberOfMatchingActivities, numberOfMatchingActivities)); for (int i = 0; i <= numberOfMatchingActivities; i++) { ResolveInfo info = resolveInfo.get(i); ActivityInfo activityinfo = info.activityInfo; if (!activityinfo.packageName.equals(getPackageName())) { stringBuilder.append(activityinfo.loadLabel(pm)) .append(getResources().getString(R.string.open_bracket)) .append(activityinfo.packageName).append(getResources().getString(R.string.dash)) .append(activityinfo.name) .append(getResources().getString(R.string.close_bracket_break)); } } } return Html.fromHtml(stringBuilder.toString()); }
From source file:com.amaze.filemanager.fragments.MainFragment.java
public static void launchSMB(final HybridFileParcelable baseFile, final Activity activity) { final Streamer s = Streamer.getInstance(); new Thread() { public void run() { try { /*//from w w w . j a v a 2 s . co m List<SmbFile> subtitleFiles = new ArrayList<SmbFile>(); // finding subtitles for (Layoutelements layoutelement : LIST_ELEMENTS) { SmbFile smbFile = new SmbFile(layoutelement.getDesc()); if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile); } */ s.setStreamSrc(new SmbFile(baseFile.getPath()), baseFile.getSize()); activity.runOnUiThread(() -> { try { Uri uri = Uri.parse(Streamer.URL + Uri .fromFile(new File(Uri.parse(baseFile.getPath()).getPath())).getEncodedPath()); Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory())); PackageManager packageManager = activity.getPackageManager(); List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0); if (resInfos != null && resInfos.size() > 0) activity.startActivity(i); else Toast.makeText(activity, activity.getResources().getString(R.string.smb_launch_error), Toast.LENGTH_SHORT).show(); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
From source file:com.android.leanlauncher.IconCache.java
public ArrayMap<String, String> getAvailableIconPacks() { ArrayMap<String, String> availableIconPacks = new ArrayMap<>(); PackageManager pm = mContext.getPackageManager(); // fetch installed icon packs for popular launchers Intent novaIntent = new Intent(Intent.ACTION_MAIN); novaIntent.addCategory(NOVA_LAUNCHER_THEME_NAME); List<ResolveInfo> novaTheme = pm.queryIntentActivities(novaIntent, PackageManager.GET_META_DATA); List<ResolveInfo> goTheme = pm.queryIntentActivities(new Intent(GO_LAUNCHER_THEME_NAME), PackageManager.GET_META_DATA); // merge those lists List<ResolveInfo> rinfo = new ArrayList<>(novaTheme); rinfo.addAll(goTheme);//from w w w . j a v a 2 s . c o m for (ResolveInfo ri : rinfo) { String packageName = ri.activityInfo.packageName; try { ApplicationInfo ai = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); String label = pm.getApplicationLabel(ai).toString(); Log.d(TAG, "Icon package = " + packageName + " title " + label); availableIconPacks.put(packageName, label); } catch (NameNotFoundException e) { Log.e(TAG, "Package not found = " + e); } } return availableIconPacks; }
From source file:com.adjust.sdk.ActivityHandler.java
private void launchDeeplinkMain(String deeplink) { if (deeplink == null) return;//from w w w . j a va 2 s. co m Uri location = Uri.parse(deeplink); Intent mapIntent = new Intent(Intent.ACTION_VIEW, location); mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Verify it resolves PackageManager packageManager = adjustConfig.context.getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(mapIntent, 0); boolean isIntentSafe = activities.size() > 0; // Start an activity if it's safe if (!isIntentSafe) { logger.error("Unable to open deep link (%s)", deeplink); return; } logger.info("Open deep link (%s)", deeplink); adjustConfig.context.startActivity(mapIntent); }
From source file:com.jtechme.apphub.FDroidApp.java
public void sendViaBluetooth(Activity activity, int resultCode, String packageName) { if (resultCode == Activity.RESULT_CANCELED) return;//www . j a va 2s. c o m String bluetoothPackageName = null; String className = null; boolean found = false; Intent sendBt = null; try { PackageManager pm = getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); sendBt = new Intent(Intent.ACTION_SEND); // The APK type is blocked by stock Android, so use zip // sendBt.setType("application/vnd.android.package-archive"); sendBt.setType("application/zip"); sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir)); // not all devices have the same Bluetooth Activities, so // let's find it for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) { bluetoothPackageName = info.activityInfo.packageName; if ("com.android.bluetooth".equals(bluetoothPackageName) || "com.mediatek.bluetooth".equals(bluetoothPackageName)) { className = info.activityInfo.name; found = true; break; } } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Could not get application info to send via bluetooth", e); found = false; } if (sendBt != null) { if (found) { sendBt.setClassName(bluetoothPackageName, className); activity.startActivity(sendBt); } else { Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show(); activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send))); } } }
From source file:de.baumann.thema.RequestActivity.java
@SuppressWarnings("unchecked") private void prepareData() // Sort the apps { ArrayList<AppInfo> arrayList = new ArrayList(); PackageManager pm = getPackageManager(); Intent intent = new Intent("android.intent.action.MAIN", null); intent.addCategory("android.intent.category.LAUNCHER"); List list = pm.queryIntentActivities(intent, 0); Iterator localIterator = list.iterator(); if (DEBUG)/*ww w. j av a 2 s . c o m*/ Log.v(TAG, "list.size(): " + list.size()); for (int i = 0; i < list.size(); i++) { ResolveInfo resolveInfo = (ResolveInfo) localIterator.next(); // This is the main part where the already styled apps are sorted out. if ((list_activities .indexOf(resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name) == -1)) { AppInfo tempAppInfo = new AppInfo( resolveInfo.activityInfo.packageName + "/" + resolveInfo.activityInfo.name, //Get package/activity resolveInfo.loadLabel(pm).toString(), //Get the app name getHighResIcon(pm, resolveInfo) //Loads xxxhdpi icon, returns normal if it on fail //Unselect icon per default ); arrayList.add(tempAppInfo); // This is just for debugging if (DEBUG) Log.i(TAG, "Added app: " + resolveInfo.loadLabel(pm)); } else { // This is just for debugging if (DEBUG) Log.v(TAG, "Removed app: " + resolveInfo.loadLabel(pm)); } } Collections.sort(arrayList, new Comparator<AppInfo>() { //Custom comparator to ensure correct sorting for characters like and apps starting with a small letter like iNex @Override public int compare(AppInfo object1, AppInfo object2) { Locale locale = Locale.getDefault(); Collator collator = Collator.getInstance(locale); collator.setStrength(Collator.TERTIARY); if (DEBUG) Log.v(TAG, "Comparing \"" + object1.getName() + "\" to \"" + object2.getName() + "\""); return collator.compare(object1.getName(), object2.getName()); } }); list_activities_final = arrayList; }
From source file:org.fdroid.fdroid.FDroidApp.java
public void sendViaBluetooth(Activity activity, int resultCode, String packageName) { if (resultCode == Activity.RESULT_CANCELED) { return;/*w w w.j a v a 2 s . co m*/ } String bluetoothPackageName = null; String className = null; boolean found = false; Intent sendBt = null; try { PackageManager pm = getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); sendBt = new Intent(Intent.ACTION_SEND); // The APK type is blocked by stock Android, so use zip // sendBt.setType("application/vnd.android.package-archive"); sendBt.setType("application/zip"); sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir)); // not all devices have the same Bluetooth Activities, so // let's find it for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) { bluetoothPackageName = info.activityInfo.packageName; if ("com.android.bluetooth".equals(bluetoothPackageName) || "com.mediatek.bluetooth".equals(bluetoothPackageName)) { className = info.activityInfo.name; found = true; break; } } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Could not get application info to send via bluetooth", e); found = false; } if (sendBt != null) { if (found) { sendBt.setClassName(bluetoothPackageName, className); activity.startActivity(sendBt); } else { Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show(); activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send))); } } }
From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java
public static void launchSMB(final SmbFile smbFile, final long si, final Activity activity) { final Streamer s = Streamer.getInstance(); new Thread() { public void run() { try { /*//from w ww. j a v a 2 s . com List<SmbFile> subtitleFiles = new ArrayList<SmbFile>(); // finding subtitles for (Layoutelements layoutelement : LIST_ELEMENTS) { SmbFile smbFile = new SmbFile(layoutelement.getDesc()); if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile); } */ s.setStreamSrc(smbFile, si); activity.runOnUiThread(new Runnable() { public void run() { try { Uri uri = Uri.parse(Streamer.URL + Uri.fromFile(new File(Uri.parse(smbFile.getPath()).getPath())) .getEncodedPath()); Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, MimeTypes.getMimeType(new File(smbFile.getPath()))); PackageManager packageManager = activity.getPackageManager(); List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0); if (resInfos != null && resInfos.size() > 0) activity.startActivity(i); else Toast.makeText(activity, activity.getResources().getString(R.string.smb_launch_error), Toast.LENGTH_SHORT).show(); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
From source file:com.goftagram.telegram.messenger.NotificationsController.java
private static String getLauncherClassName(Context context) { try {//from w w w . ja va 2s . co m PackageManager pm = context.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0); for (ResolveInfo resolveInfo : resolveInfos) { String pkgName = resolveInfo.activityInfo.applicationInfo.packageName; if (pkgName.equalsIgnoreCase(context.getPackageName())) { return resolveInfo.activityInfo.name; } } } catch (Throwable e) { FileLog.e("tmessages", e); } return null; }