List of usage examples for android.content.pm PackageManager GET_RESOLVED_FILTER
int GET_RESOLVED_FILTER
To view the source code for android.content.pm PackageManager GET_RESOLVED_FILTER.
Click Source Link
From source file:Main.java
/** * Check whether the given package is a specialized handler for the given intent * * @param context {@link Context} to use for getting the {@link PackageManager}. * @param packageName Package name to check against. Can be null or empty. * @param intent The intent to resolve for. * @return Whether the given package is a specialized handler for the given intent. If there is * no package name given checks whether there is any specialized handler. *//*from ww w .j a va2 s .c o m*/ public static boolean isPackageSpecializedHandler(Context context, String packageName, Intent intent) { try { List<ResolveInfo> handlers = context.getPackageManager().queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); if (handlers == null || handlers.size() == 0) return false; for (ResolveInfo resolveInfo : handlers) { IntentFilter filter = resolveInfo.filter; if (filter == null) { // No intent filter matches this intent? // Error on the side of staying in the browser, ignore continue; } if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) { // Generic handler, skip continue; } if (TextUtils.isEmpty(packageName)) return true; ActivityInfo activityInfo = resolveInfo.activityInfo; if (activityInfo == null) continue; if (!activityInfo.packageName.equals(packageName)) continue; return true; } } catch (RuntimeException e) { Log.e(TAG, "isPackageSpecializedHandler e=" + e); } return false; }
From source file:Main.java
public static String getMainProcessName(Context context) { Intent it = new Intent(Intent.ACTION_MAIN); it.setPackage(context.getPackageName()); ResolveInfo info = context.getPackageManager().resolveActivity(it, PackageManager.GET_RESOLVED_FILTER); String processName = null;//from w ww . j av a 2 s . c o m if (info != null && info.activityInfo != null) { processName = info.activityInfo.processName; } else { processName = context.getPackageName(); } return processName; }
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 {/* www.j ava2 s . c om*/ 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:Main.java
/** * Used to check whether there is a specialized handler for a given intent. * @param intent The intent to check with. * @return Whether there is a specialized handler for the given intent. *//*w w w . java 2 s .c o m*/ private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) { try { PackageManager pm = context.getPackageManager(); List<ResolveInfo> handlers = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); if (handlers == null || handlers.size() == 0) { return false; } for (ResolveInfo resolveInfo : handlers) { IntentFilter filter = resolveInfo.filter; if (filter == null) continue; if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue; if (resolveInfo.activityInfo == null) continue; return true; } } catch (RuntimeException e) { Log.e(TAG, "Runtime exception while getting specialized handlers"); } return false; }
From source file:com.dm.material.dashboard.candybar.tasks.IconRequestTask.java
@Override protected Boolean doInBackground(Void... voids) { while (!isCancelled()) { try {/*w w w. ja va2s . c om*/ Thread.sleep(1); if (mContext.get().getResources().getBoolean(R.bool.enable_icon_request) || mContext.get().getResources().getBoolean(R.bool.enable_premium_request)) { List<Request> requests = new ArrayList<>(); HashMap<String, String> appFilter = RequestHelper.getAppFilter(mContext.get(), RequestHelper.Key.ACTIVITY); if (appFilter.size() == 0) { mError = Extras.Error.APPFILTER_NULL; return false; } PackageManager packageManager = mContext.get().getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> installedApps = packageManager.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); if (installedApps == null || installedApps.size() == 0) { mError = Extras.Error.INSTALLED_APPS_NULL; return false; } CandyBarMainActivity.sInstalledAppsCount = installedApps.size(); try { 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; String value = appFilter.get(activity); if (value == null) { String name = LocaleHelper.getOtherAppLocaleName(mContext.get(), new Locale("en"), packageName); if (name == null) { name = app.activityInfo.loadLabel(packageManager).toString(); } boolean requested = Database.get(mContext.get()).isRequested(activity); Request request = Request.Builder().name(name).packageName(app.activityInfo.packageName) .activity(activity).requested(requested).build(); requests.add(request); } } CandyBarMainActivity.sMissedApps = requests; } return true; } catch (Exception e) { CandyBarMainActivity.sMissedApps = null; mError = Extras.Error.DATABASE_ERROR; LogUtil.e(Log.getStackTraceString(e)); return false; } } return false; }
From source file:widgets.PageWidget.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); wv = (WebView) super.getActivity().findViewById(activity.getActId()); // get the location data String url = course.getLocation() + activity.getLocation(prefs.getString(super.getActivity().getString(R.string.prefs_language), Locale.getDefault().getLanguage())); try {/*w w w.j a v a2 s. co m*/ wv.loadDataWithBaseURL("file://" + course.getLocation() + "/", FileUtils.readFile(url), "text/html", "utf-8", null); } catch (IOException e) { wv.loadUrl("file://" + url); } // set up the page to intercept videos wv.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.contains("/video/")) { Log.d(TAG, "Intercepting click on video url: " + url); // extract video name from url int startPos = url.indexOf("/video/") + 7; mediaFileName = url.substring(startPos, url.length()); // check video file exists boolean exists = FileUtils.mediaFileExists(mediaFileName); if (!exists) { Toast.makeText(PageWidget.super.getActivity(), PageWidget.super.getActivity() .getString(R.string.error_media_not_found, mediaFileName), Toast.LENGTH_LONG) .show(); return true; } String mimeType = FileUtils.getMimeType(MobileLearning.MEDIA_PATH + mediaFileName); if (!FileUtils.supportedMediafileType(mimeType)) { Toast.makeText(PageWidget.super.getActivity(), PageWidget.super.getActivity() .getString(R.string.error_media_unsupported, mediaFileName), Toast.LENGTH_LONG) .show(); return true; } // check user has app installed to play the video // launch intent to play video Intent intent = new Intent(android.content.Intent.ACTION_VIEW); Uri data = Uri.parse(MobileLearning.MEDIA_PATH + mediaFileName); intent.setDataAndType(data, "video/mp4"); PackageManager pm = PageWidget.super.getActivity().getPackageManager(); List<ResolveInfo> infos = pm.queryIntentActivities(intent, PackageManager.GET_RESOLVED_FILTER); boolean appFound = false; for (ResolveInfo info : infos) { IntentFilter filter = info.filter; if (filter != null && filter.hasAction(Intent.ACTION_VIEW)) { // Found an app with the right intent/filter appFound = true; } } if (!appFound) { Toast.makeText(PageWidget.super.getActivity(), PageWidget.super.getActivity().getString(R.string.error_media_app_not_found), Toast.LENGTH_LONG).show(); return true; } PageWidget.this.mediaPlaying = true; PageWidget.this.mediaStartTimeStamp = System.currentTimeMillis() / 1000; PageWidget.super.getActivity().startActivity(intent); return true; } else { Intent intent = new Intent(Intent.ACTION_VIEW); Uri data = Uri.parse(url); intent.setData(data); PageWidget.super.getActivity().startActivity(intent); // launch action in mobile browser - not the webview // return true so doesn't follow link within webview return true; } } }); }
From source file:com.dm.material.dashboard.candybar.helpers.ReportBugsHelper.java
@Nullable private static String buildActivityList(Context context, File folder) { try {//from ww w .j av a2s .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:util.mediamanager.PlaylistUtils.java
public static void ListMediaButtonReceivers(Context context, String query) { try {/* w ww .j a va 2 s. c o m*/ final Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> mediaReceivers = packageManager.queryBroadcastReceivers(mediaButtonIntent, PackageManager.GET_INTENT_FILTERS | PackageManager.GET_RESOLVED_FILTER); for (int i = mediaReceivers.size() - 1; i >= 0; i--) { ResolveInfo mediaReceiverResolveInfo = mediaReceivers.get(i); String name = mediaReceiverResolveInfo.activityInfo.applicationInfo.sourceDir + ", " + mediaReceiverResolveInfo.activityInfo.name; String cn = mediaReceiverResolveInfo.resolvePackageName; String cn1 = mediaReceiverResolveInfo.activityInfo.toString(); Log.d(Constants.APP.TAG, "resolvePackageName media receivers = " + cn); Log.d(Constants.APP.TAG, "activityInfo = " + cn1); } mediaButtonIntent.setAction(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH); //mediaButtonIntent.setComponent(new ComponentName("com.spotify.music", "com.spotify.music.MainActivity")); mediaButtonIntent.putExtra(SearchManager.QUERY, "GM1"); mediaButtonIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); context.startActivity(mediaButtonIntent); } catch (ActivityNotFoundException e) { Log.e(Constants.APP.TAG, "Error searching Spotify w/ query '" + query + "'"); //Toast.makeText(mRideManager.mAppContext, String.format("Error parsing query \"%s\"", query), Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }
From source file:com.kccomy.orgar.ui.note.NoteFragment.java
private void initPopupWindow() { View popupWindowView = getActivity().getLayoutInflater().inflate(R.layout.popup_window_share, null); //??/* w ww. j a va2s . co m*/ Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addCategory(Intent.CATEGORY_DEFAULT); shareIntent.setType("text/plain"); PackageManager packageManager = getContext().getPackageManager(); List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(shareIntent, PackageManager.GET_RESOLVED_FILTER); // RecyclerAdapter RecyclerView recyclerView = (RecyclerView) popupWindowView.findViewById(R.id.popup_widow_share_recycler); ShareAdapter shareAdapter = new ShareAdapter(packageManager); shareAdapter.setData(resolveInfos); shareAdapter.setAppIconClickListener(shareListener); recyclerView.setAdapter(shareAdapter); recyclerView .setLayoutManager(new GridLayoutManager(getContext(), 2, LinearLayoutManager.HORIZONTAL, false)); // ?PopupWindow popupWindowView.setFocusable(true); popupWindowView.setFocusableInTouchMode(true); PopupWindow popupWindow = new PopupWindow(popupWindowView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000)); popupWindow.setAnimationStyle(R.style.anim_menu_bottombar); setWindowAlpha(0.5f); popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { setWindowAlpha(1f); } }); popupWindow.showAtLocation(getActivity().getLayoutInflater().inflate(R.layout.fragment_note, null), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); }
From source file:com.samsung.multiwindow.MultiWindow.java
/** * Get the MultiWindow enabled applications and activity names * /* w w w. j a va2 s. co m*/ * @param windowType * The window type freestyle or splitstyle. * @param callbackContext * The callback id used when calling back into JavaScript. * */ private void getMultiWindowApps(final String windowType, final CallbackContext callbackContext) throws JSONException { if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) { Log.d(TAG, "Inside getMultiWindowApps"); } cordova.getThreadPool().execute(new Runnable() { public void run() { JSONArray multiWindowApps = new JSONArray(); Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> resolveInfos = cordova.getActivity().getPackageManager().queryIntentActivities( intent, PackageManager.GET_RESOLVED_FILTER | PackageManager.GET_META_DATA); try { // Get the multiwindow enabled applications int index = 0; for (ResolveInfo r : resolveInfos) { if (r.activityInfo != null && r.activityInfo.applicationInfo.metaData != null) { if (r.activityInfo.applicationInfo.metaData .getBoolean("com.sec.android.support.multiwindow") || r.activityInfo.applicationInfo.metaData .getBoolean("com.samsung.android.sdk.multiwindow.enable")) { JSONObject appInfo = new JSONObject(); boolean bUnSupportedMultiWinodw = false; if (windowType.equalsIgnoreCase("splitstyle")) { if (r.activityInfo.metaData != null) { String activityWindowStyle = r.activityInfo.metaData .getString("com.sec.android.multiwindow.activity.STYLE"); if (activityWindowStyle != null) { ArrayList<String> activityWindowStyles = new ArrayList<String>( Arrays.asList(activityWindowStyle.split("\\|"))); if (!activityWindowStyles.isEmpty()) { if (activityWindowStyles.contains("fullscreenOnly")) { bUnSupportedMultiWinodw = true; } } } } } if (!bUnSupportedMultiWinodw || !windowType.equalsIgnoreCase("splitstyle")) { appInfo.put("packageName", r.activityInfo.applicationInfo.packageName); appInfo.put("activity", r.activityInfo.name); multiWindowApps.put(index++, appInfo); } } } } callbackContext.success(multiWindowApps); } catch (Exception e) { callbackContext.error(e.getMessage()); } } }); }