List of usage examples for android.app Activity getPackageManager
@Override
public PackageManager getPackageManager()
From source file:Main.java
@TargetApi(16) static void setAndroidBeam(Activity activity, String packageName) { if (Build.VERSION.SDK_INT < 16) return;/* www.j a v a2 s .co m*/ PackageManager pm = activity.getPackageManager(); NfcAdapter nfcAdapter = getAdapter(activity); if (nfcAdapter != null) { ApplicationInfo appInfo; try { appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); Uri uris[] = { Uri.parse("file://" + appInfo.publicSourceDir), }; nfcAdapter.setBeamPushUris(uris, activity); } catch (NameNotFoundException e) { e.printStackTrace(); } } }
From source file:Main.java
public static String getApplicationName(Activity context) { PackageManager packageManager = null; ApplicationInfo applicationInfo = null; try {/* ww w .ja va 2 s .c o m*/ packageManager = context.getPackageManager(); applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { applicationInfo = null; } return (String) packageManager.getApplicationLabel(applicationInfo); }
From source file:Main.java
public static boolean startActivity(Activity a, String packageName, Bundle args) { PackageManager pm = a.getPackageManager(); boolean result = true; try {/*from ww w. j a v a 2s . co m*/ Intent intent = pm.getLaunchIntentForPackage(packageName); if (null != intent) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (args != null) intent.putExtras(args); a.startActivity(intent); } else { result = startActivityUsingScheme(a, packageName, args); } } catch (Exception e) { Log.e(a.getClass().getName(), e.getMessage(), e); result = startActivityUsingScheme(a, packageName, args); } return result; }
From source file:Main.java
public static boolean startActivity(Activity a, String packageName, Bundle args, int flags) { PackageManager pm = a.getPackageManager(); boolean result = true; try {//from w w w . j ava 2 s. co m Intent intent = pm.getLaunchIntentForPackage(packageName); if (null != intent) { intent.addFlags(flags); if (args != null) intent.putExtras(args); a.startActivity(intent); } } catch (Exception e) { Log.e(a.getClass().getName(), e.getMessage(), e); result = false; } return result; }
From source file:fi.danielsan.donkino.ui.Navigator.java
public static void startYoutubeIntent(@NonNull Activity activity, @NonNull String videoId) { Timber.d("Youtube intent: " + videoId); if (isAppInstalled(activity.getPackageManager(), "com.google.android.youtube")) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + videoId)); intent.putExtra("VIDEO_ID", videoId); activity.startActivity(intent);/*from ww w. j av a 2 s. c o m*/ } }
From source file:com.github.fi3te.iliasdownloader.view.Eula.java
private static PackageInfo getPackageInfo(Activity activity) { PackageInfo pi = null;/* www . ja v a 2 s . c om*/ try { pi = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return pi; }
From source file:Main.java
public static Boolean isCameraAvailable(Activity activity) { Log.d(TAG, "[AirImagePickerUtils] Entering isCameraAvailable"); Boolean hasCameraFeature = activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA); Boolean hasFrontCameraFeature = activity.getPackageManager() .hasSystemFeature("android.hardware.camera.front"); Boolean isAvailable = (hasFrontCameraFeature || hasCameraFeature) && (isActionAvailable(activity, CAMERA_IMAGE_ACTION) || isActionAvailable(activity, CAMERA_VIDEO_ACTION)); Log.d(TAG, "[AirImagePickerUtils] Exiting isCameraAvailable"); return isAvailable; }
From source file:Main.java
public static void getCameraFromSelfCenter(Activity activity, boolean openFrontCamera) { initData(activity);/*from w w w . j a va 2 s .c om*/ Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); Intent intent_camera = activity.getPackageManager().getLaunchIntentForPackage("com.android.camera"); if (intent_camera != null) { intent.setPackage("com.android.camera"); } if (openFrontCamera) { intent.putExtra("android.intent.extras.CAMERA_FACING", 1); } intent.putExtra(MediaStore.EXTRA_OUTPUT, mAvatarUri); activity.startActivityForResult(intent, REQUEST_TAKE_PICTURE_SELF_CENTER); }
From source file:Main.java
public static Boolean isCropAvailable(Activity activity) { Log.d(TAG, "[AirImagePickerUtils] isCropAvailable"); final PackageManager packageManager = activity.getPackageManager(); Intent intent = getIntentForAction(CROP_ACTION); intent.setType("image/*"); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); Log.d(TAG, "[AirImagePickerUtils] Exiting isCropAvailable"); return list.size() > 0; }
From source file:com.monmonja.library.utils.PlayServiceUtils.java
public static boolean isSpeechRecognitionActivityPresented(Activity callerActivity) { try {//from w ww .j a v a 2s. c o m // getting an instance of package manager PackageManager pm = callerActivity.getPackageManager(); // a list of activities, which can process speech recognition Intent List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); if (activities.size() != 0) { // if list not empty return true; // then we can recognize the speech } } catch (Exception e) { } return false; // we have no activities to recognize the speech }