List of usage examples for android.content.pm PackageManager resolveActivity
public abstract ResolveInfo resolveActivity(Intent intent, @ResolveInfoFlags int flags);
From source file:com.linkbubble.util.Util.java
static public boolean isDefaultBrowser(String currentPackageName, PackageManager packageManager) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com")); final ResolveInfo info = packageManager.resolveActivity(i, 0); if (info != null) { if (info.activityInfo.applicationInfo.packageName.equals(currentPackageName)) { return true; }//from w w w . j a v a 2 s . co m } return false; }
From source file:com.linkbubble.util.Util.java
static public ResolveInfo getDefaultBrowser(PackageManager packageManager) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(Config.SET_DEFAULT_BROWSER_URL)); return packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); }
From source file:com.linkbubble.util.Util.java
static public String getDefaultLauncherPackage(PackageManager packageManager) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); ResolveInfo resolveInfo = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfo != null && resolveInfo.activityInfo != null) { if (resolveInfo.activityInfo.packageName.equals("android") == false) { //setDefaultLauncherPreference.setSummary(R.string.not_default_youtube_app); return resolveInfo.activityInfo.packageName; }/* w w w. j a v a2 s . c o m*/ } return null; }
From source file:com.example.android.home.Home.java
/** * Refreshes the recently launched applications stacked over the favorites. The number * of recents depends on how many favorites are present. *///w ww .j a va 2s. c om /* private void bindRecents() { final PackageManager manager = getPackageManager(); final ActivityManager tasksManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); final List<ActivityManager.RecentTaskInfo> recentTasks = tasksManager.getRecentTasks( MAX_RECENT_TASKS, 0); final int count = recentTasks.size(); final ArrayList<ApplicationInfo> recents = new ArrayList<ApplicationInfo>(); for (int i = count - 1; i >= 0; i--) { final Intent intent = recentTasks.get(i).baseIntent; if (Intent.ACTION_MAIN.equals(intent.getAction()) && !intent.hasCategory(Intent.CATEGORY_HOME)) { ApplicationInfo info = getApplicationInfo(manager, intent); if (info != null) { info.intent = intent; // if (!mFavorites.contains(info)) { // recents.add(info); // } } } } //mApplicationsStack.setRecents(recents); } */ private static ApplicationInfo getApplicationInfo(PackageManager manager, Intent intent) { final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0); if (resolveInfo == null) { return null; } final ApplicationInfo info = new ApplicationInfo(); final ActivityInfo activityInfo = resolveInfo.activityInfo; info.icon = activityInfo.loadIcon(manager); if (info.title == null || info.title.length() == 0) { info.title = activityInfo.loadLabel(manager); } if (info.title == null) { info.title = ""; } return info; }
From source file:net.simonvt.cathode.ui.dialog.AboutDialog.java
private void openUrl(String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); PackageManager pm = getActivity().getPackageManager(); if (pm.resolveActivity(intent, 0) != null) { startActivity(intent);/*from ww w .j a v a2s .co m*/ } }
From source file:org.chromium.chrome.browser.download.OMADownloadHandler.java
/** * Returns the first MIME type in the OMA download that can be opened on the device. * * @param pm PackageManger for the current context. * @param omaInfo Information about the OMA content. * @return the MIME type can be opened by the device. *//*from ww w . j a v a 2 s .c om*/ static String getOpennableType(PackageManager pm, OMAInfo omaInfo) { if (omaInfo.isValueEmpty(OMA_OBJECT_URI)) { return null; } Intent intent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse(omaInfo.getValue(OMA_OBJECT_URI)); for (String type : omaInfo.getTypes()) { if (!type.equalsIgnoreCase(OMA_DRM_MESSAGE_MIME) && !type.equalsIgnoreCase(OMA_DRM_CONTENT_MIME) && !type.equalsIgnoreCase(OMA_DOWNLOAD_DESCRIPTOR_MIME) && !type.equalsIgnoreCase(OMA_DRM_RIGHTS_MIME)) { intent.setDataAndType(uri, type); ResolveInfo resolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfo != null) { return type; } } } return null; }
From source file:org.kontalk.ui.DonationFragment.java
private void donateBitcoin() { final String address = getString(R.string.bitcoin_address); Uri uri = Uri.parse("bitcoin:" + address); Intent intent = SystemUtils.externalIntent(Intent.ACTION_VIEW, Uri.parse(uri.toString())); Activity ctx = getActivity();/*www .j av a2 s.c o m*/ final PackageManager pm = ctx.getPackageManager(); if (pm.resolveActivity(intent, 0) != null) startActivity(intent); else new MaterialDialog.Builder(getActivity()).title(R.string.title_bitcoin_dialog) .content(getString(R.string.text_bitcoin_dialog, address)).positiveText(android.R.string.ok) .neutralText(R.string.copy_clipboard).onNeutral(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { ClipboardManager cpm = (ClipboardManager) getActivity() .getSystemService(Context.CLIPBOARD_SERVICE); cpm.setText(address); Toast.makeText(getActivity(), R.string.bitcoin_clipboard_copied, Toast.LENGTH_LONG) .show(); } }).show(); }
From source file:com.farmerbb.secondscreen.util.U.java
public static String uiRefreshCommand2(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); // For better reliability, we execute the UI refresh while on the home screen Intent homeIntent = new Intent(Intent.ACTION_MAIN); homeIntent.addCategory(Intent.CATEGORY_HOME); homeIntent.addCategory(Intent.CATEGORY_DEFAULT); homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(homeIntent);// ww w . j a v a2 s .c om // Kill all background processes, in order to fully refresh UI PackageManager pm = context.getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(0); for (ApplicationInfo packageInfo : packages) { if (!packageInfo.packageName.equalsIgnoreCase(context.getPackageName())) am.killBackgroundProcesses(packageInfo.packageName); } // Get launcher package name final ResolveInfo mInfo = pm.resolveActivity(homeIntent, 0); return "sleep 1 && am force-stop " + mInfo.activityInfo.applicationInfo.packageName; }
From source file:ee.ria.DigiDoc.fragment.ContainerDataFilesFragment.java
private Intent createChooserOrViewIntentForDataFile(DataFileFacade dataFileFacade) { String fileName = dataFileFacade.getFileName(); String mediaType = FileUtils.resolveMimeType(fileName); Uri contentUri = createShareUri(fileName); if (FileUtils.isContainer(fileName)) { return createViewIntent(contentUri, mediaType); }//from w w w . j a v a2s .c o m Intent viewIntent = createViewIntent(contentUri, mediaType); PackageManager packageManager = getActivity().getPackageManager(); List<ResolveInfo> allAvailableResolvers = packageManager.queryIntentActivities(viewIntent, 0); ResolveInfo defaultResolver = packageManager.resolveActivity(viewIntent, 0); Map<String, Intent> targetedIntents = createdTargetedViewIntentsForResolvers(allAvailableResolvers, contentUri, mediaType); if (targetedIntents.isEmpty()) { throw new FailedToCreateViewIntentException(getText(R.string.file_handler_error)); } else if (targetedIntents.size() == 1) { return targetedIntents.values().iterator().next(); } else if (targetedIntents.containsKey(resolvePackageName(defaultResolver))) { return targetedIntents.get(resolvePackageName(defaultResolver)); } else { return createChooser(new ArrayList<>(targetedIntents.values()), getText(R.string.open_file_with)); } }
From source file:owne.android.envmonitor.FeaturesActivity.java
private void setupPluginsInDrawer(final ViewGroup container) { final LayoutInflater inflater = LayoutInflater.from(this); final PackageManager pm = getPackageManager(); // look for Master Control Panel final Intent mcpIntent = new Intent(Intent.ACTION_MAIN); mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS); final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0); // configure link to Master Control Panel final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp); if (mcpInfo == null) { mcpItem.setTextColor(Color.GRAY); ColorMatrix grayscale = new ColorMatrix(); grayscale.setSaturation(0.0f);/*from w ww. j a v a2s . com*/ mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale)); } mcpItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { Intent action = mcpIntent; if (mcpInfo == null) action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI)); action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(action); mDrawerLayout.closeDrawers(); } }); // look for other plug-ins final Intent utilsIntent = new Intent(Intent.ACTION_MAIN); utilsIntent.addCategory(UTILS_CATEGORY); final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0); for (final ResolveInfo info : appList) { final View item = inflater.inflate(R.layout.drawer_plugin, container, false); final ImageView icon = (ImageView) item.findViewById(android.R.id.icon); final TextView label = (TextView) item.findViewById(android.R.id.text1); label.setText(info.loadLabel(pm)); icon.setImageDrawable(info.loadIcon(pm)); item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { final Intent intent = new Intent(); intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name)); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); } }); container.addView(item); } }