List of usage examples for android.content.pm PackageManager queryIntentActivities
public abstract List<ResolveInfo> queryIntentActivities(Intent intent, @ResolveInfoFlags int flags);
From source file:com.yahala.android.NotificationsController.java
public static String getLauncherClassName(Context context) { try {/*from w w w . j a v a 2 s .c o 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 (Exception e) { FileLog.e("tmessages", e); } return null; }
From source file:com.jungle.base.utils.MiscUtils.java
public static String getMainLauncherActivity() { try {/*from w w w . j a v a 2 s . c o m*/ Context context = BaseApplication.getAppContext(); PackageManager manager = context.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> list = manager.queryIntentActivities(intent, 0); Collections.sort(list, new ResolveInfo.DisplayNameComparator(manager)); String packageName = MiscUtils.getPackageName(); for (ResolveInfo info : list) { if (TextUtils.equals(packageName, info.activityInfo.packageName)) { return info.activityInfo.name; } } } catch (Throwable e) { e.printStackTrace(); } return null; }
From source file:com.lee.sdk.utils.Utils.java
/** * Indicates whether the specified action can be used as an intent. This method queries the * package manager for installed packages that can respond to an intent with the specified * action. If no suitable package is found, this method returns false. * /*from w w w . j a v a 2 s . c o m*/ * @param context The application's environment. * @param intent The Intent action to check for availability. * * @return True if an Intent with the specified action can be sent and responded to, false * otherwise. */ public static boolean isIntentAvailable(Context context, Intent intent) { final PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PackageManager pm = getPackageManager(); List<ResolveInfo> activities = pm .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() == 0) { findViewById(R.id.imageButton).setEnabled(false); Toast.makeText(this, "Speech Recognition Not Supported", Toast.LENGTH_LONG).show(); }//from w w w .j a v a 2 s . c om SpeechRecognizer speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this); }
From source file:com.trigger_context.conf.Action_Post_Tweet.java
public Intent findTwitterClient() { final String[] twitterApps = { "com.twitter.android", // official - 10 // 000 "com.twidroid", // twidroid - 5 000 "com.handmark.tweetcaster", // Tweetcaster - 5 000 "com.thedeck.android" }; // TweetDeck - 5 000 ; Intent tweetIntent = new Intent(); tweetIntent.setType("text/plain"); final PackageManager packageManager = getPackageManager(); List<ResolveInfo> list = packageManager.queryIntentActivities(tweetIntent, PackageManager.MATCH_DEFAULT_ONLY); for (String twitterApp : twitterApps) { for (ResolveInfo resolveInfo : list) { String p = resolveInfo.activityInfo.packageName; if (p != null && p.startsWith(twitterApp)) { tweetIntent.setPackage(p); return tweetIntent; }//from w ww .ja v a 2s . c om } } return null; }
From source file:com.yalin.fidoclient.ui.fragment.AsmListFragment.java
private void initData() { Intent intent = ASMIntent.getASMIntent(); PackageManager pm = getActivity().getApplicationContext().getPackageManager(); List<ResolveInfo> infos = pm.queryIntentActivities(intent, PackageManager.GET_INTENT_FILTERS); if (infos != null && infos.size() > 0) { AsmListAdapter asmListAdapter = new AsmListAdapter(getActivity(), infos, this); rvAsmList.setAdapter(asmListAdapter); } else {/*from www . ja va2 s.c o m*/ tvAsmListPrompt.setText(R.string.no_asm); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { try {//from ww w .j ava 2 s .c om String packageName = obj.getString(PACKAGE_NAME); String feedName = obj.getString("sharedFeedName"); JSONArray ids = obj.getJSONArray(PARTICIPANTS); Intent launch = new Intent(); launch.setAction(Intent.ACTION_MAIN); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.putExtra("type", "invite_app_feed"); launch.putExtra("creator", false); launch.putExtra("sender", from.id); launch.putExtra("sharedFeedName", feedName); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); long[] idArray = new long[ids.length()]; for (int i = 0; i < ids.length(); i++) { idArray[i] = ids.getLong(i); } launch.putExtra("participants", idArray); launch.setPackage(packageName); final PackageManager mgr = context.getPackageManager(); List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0); if (resolved.size() == 0) { Toast.makeText(context, "Could not find application to handle invite.", Toast.LENGTH_SHORT).show(); return; } ActivityInfo info = resolved.get(0).activityInfo; launch.setComponent(new ComponentName(info.packageName, info.name)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New Invitation from " + from.name, "Invitation received from " + from.name, "Click to launch application: " + packageName, contentIntent); } catch (JSONException e) { Log.e(TAG, e.getMessage()); } }
From source file:org.intermine.app.activity.GeneViewActivity.java
protected void shareText() { Intent intent = Sharing.generateIntentToSendText(mGene); PackageManager manager = getPackageManager(); List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0); if (infos.size() > 0) { startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_message))); } else {/*w w w . ja v a 2 s . co m*/ Toast.makeText(this, "No messenger installed.", Toast.LENGTH_SHORT).show(); } }
From source file:com.ntsync.android.sync.activities.MainActivity.java
private void initViewPeopleBtn() { TextView startBtn = (TextView) findViewById(R.id.btnPeople); Intent contactAppIntent = ContactManager.createContactAppIntent(); boolean isIntentSafe = false; if (contactAppIntent != null) { PackageManager packageManager = getPackageManager(); List<ResolveInfo> activities = packageManager.queryIntentActivities(contactAppIntent, 0); isIntentSafe = !activities.isEmpty(); Drawable icon = ContactManager.getContactAppIcon(this, contactAppIntent); startBtn.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null); }//from w w w. j av a 2 s .c o m startBtn.setEnabled(isIntentSafe); }
From source file:com.example.SpeechRecognizer.java
/** * Checks if a recognizer is present on this device *///w ww.j a v a 2 s.c o m private boolean IsSpeechRecognizerPresent() { PackageManager pm = ctx.getPackageManager(); List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); return !activities.isEmpty(); }