List of usage examples for android.app Activity getPackageName
@Override
public String getPackageName()
From source file:com.king.base.util.SystemUtils.java
/** * ?//from www .j ava 2s . c o m * * @param activity * @param path * @param requestCode */ public static void imageCapture(Activity activity, String path, int requestCode) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (!TextUtils.isEmpty(path)) { Uri uri = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { uri = FileProvider.getUriForFile(activity, activity.getPackageName() + ".fileProvider", new File(path)); } else { uri = Uri.fromFile(new File(path)); } intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); } activity.startActivityForResult(intent, requestCode); }
From source file:com.base.utils.permission.EasyPermissions.java
@TargetApi(11) public static void startAppSettings(Object object) { final Activity activity = getActivity(object); if (null == activity) { return;/*from w w w . j ava 2 s.co m*/ } Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", activity.getPackageName(), null); intent.setData(uri); startAppSettingsScreen(object, intent); }
From source file:com.sean.nanastudio.taoyuanstreetparking.MainActivity.java
public static void startInstalledAppDetailsActivity(final Activity context) { if (context == null) { return;/*w w w . j a va 2 s . c o m*/ } final Intent i = new Intent(); i.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); i.addCategory(Intent.CATEGORY_DEFAULT); i.setData(Uri.parse("package:" + context.getPackageName())); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); context.startActivity(i); }
From source file:com.google.android.apps.forscience.whistlepunk.PictureUtils.java
public static void launchExternalViewer(Activity activity, String fileUrl) { Intent intent = new Intent(Intent.ACTION_VIEW); String extension = MimeTypeMap.getFileExtensionFromUrl(fileUrl); String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (!TextUtils.isEmpty(type)) { String filePath = fileUrl; if (filePath.startsWith("file:")) { filePath = filePath.substring("file:".length()); }/*w ww . j ava 2 s . com*/ Uri photoUri = FileProvider.getUriForFile(activity, activity.getPackageName(), new File(filePath)); intent.setDataAndType(photoUri, type); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Needed to avoid security exception on KitKat. intent.setClipData(ClipData.newRawUri(null, photoUri)); } intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); try { activity.startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "No activity found to handle this " + fileUrl + " type " + type); } } else { Log.w(TAG, "Could not find mime type for " + fileUrl); } }
From source file:com.qiscus.sdk.util.QiscusPermissionsUtil.java
public static boolean checkDeniedPermissionsNeverAskAgain(Object object, String rationale, @StringRes int positiveButton, @StringRes int negativeButton, List<String> deniedPerms) { boolean shouldShowRationale; for (String perm : deniedPerms) { shouldShowRationale = shouldShowRequestPermissionRationale(object, perm); if (!shouldShowRationale) { final Activity activity = getActivity(object); if (null == activity) { return true; }/*from w w w . j av a2 s .co m*/ AlertDialog dialog = new AlertDialog.Builder(activity).setMessage(rationale) .setPositiveButton(positiveButton, (dialog1, which) -> { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", activity.getPackageName(), null); intent.setData(uri); activity.startActivity(intent); }).setNegativeButton(negativeButton, null).create(); dialog.show(); return true; } } return false; }
From source file:com.felkertech.n.ActivityUtils.java
public static void openAbout(final Activity activity) { try {/* w ww. j av a 2 s .com*/ PackageInfo pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0); new MaterialDialog.Builder(activity).title(R.string.app_name).theme(Theme.DARK) .content(activity.getString(R.string.about_app_description, pInfo.versionName)) .positiveText(R.string.website).negativeText(R.string.help) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { super.onPositive(dialog); String url = activity.getString(R.string.website_url); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); try { customTabsIntent.launchUrl(activity, Uri.parse(url)); } catch (Exception e) { // There is no way to view the website. activity.startActivity(new Intent(activity, HomepageWebViewActivity.class)); } } @Override public void onNegative(MaterialDialog dialog) { super.onNegative(dialog); ActivityUtils.openIntroVoluntarily(activity); } }).show(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:tv.ouya.sdk.OuyaUnityPlugin.java
public static String getStringResource(String name) { final Activity activity = IOuyaActivity.GetActivity(); if (null == activity) { return ""; }// w w w . ja v a 2 s . c o m Resources resources = activity.getResources(); if (null == resources) { return ""; } int id = resources.getIdentifier(name, "string", activity.getPackageName()); if (id <= 0) { return ""; } return resources.getString(id); }
From source file:cn.motalks.mtdc.utils.EasyPermissionsEx.java
/** * * prompt the user to go to the app's settings screen and enable permissions. If the * user clicks snackbar's action, they are sent to the settings screen. The result is returned * to the Activity via {@link Activity#onActivityResult(int, int, Intent)}. * * @param object Activity or Fragment requesting permissions. * @param rationale a message explaining why the application needs this set of permissions, will * be displayed on the snackbar. * @param snackbarAction text disPlayed on the snackbar's action * @param requestCode If >= 0, this code will be returned in onActivityResult() when the activity exits. *///from w ww. j a v a 2s . com public static void goSettings2Permissions(final Object object, String rationale, String snackbarAction, final int requestCode) { checkCallingObjectSuitability(object); final Activity activity = getActivity(object); if (null == activity) { return; } Snackbar.make(activity.findViewById(android.R.id.content), rationale, Snackbar.LENGTH_LONG) .setAction(snackbarAction, new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", activity.getPackageName(), null); intent.setData(uri); startForResult(object, intent, requestCode); } }).show(); }
From source file:org.noise_planet.noisecapture.MainActivity.java
/** * @return Version information on this application * @throws PackageManager.NameNotFoundException *//*from w w w. jav a2 s . c om*/ public static String getVersionString(Activity activity) throws PackageManager.NameNotFoundException { String versionName = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName; Date buildDate = new Date(BuildConfig.TIMESTAMP); String gitHash = BuildConfig.GITHASH; if (gitHash == null || gitHash.isEmpty()) { gitHash = ""; } else { gitHash = gitHash.substring(0, 7); } return activity.getString(R.string.title_appversion, versionName, DateFormat.getDateInstance().format(buildDate), gitHash); }
From source file:pub.devrel.easypermissions.EasyPermission.java
/** * OnActivityResult???//www. j a v a2 s .c om * {@link EasyPermission#hasPermissions(Context, String...)} * * If user denied permissions with the flag NEVER ASK AGAIN, open a dialog explaining the * permissions rationale again and directing the user to the app settings. After the user * returned to the app, {@link Activity#onActivityResult(int, int, Intent)} or * {@link Fragment#onActivityResult(int, int, Intent)} or * {@link android.app.Fragment#onActivityResult(int, int, Intent)} will be called with * {@value #SETTINGS_REQ_CODE} as requestCode * <p> * * NOTE: use of this method is optional, should be called from * {@link PermissionCallback#onPermissionDenied(int, List)} * * @return {@code true} if user denied at least one permission with the flag NEVER ASK AGAIN. */ public static boolean checkDeniedPermissionsNeverAskAgain(final Object object, String rationale, @StringRes int positiveButton, @StringRes int negativeButton, @Nullable DialogInterface.OnClickListener negativeButtonOnClickListener, List<String> deniedPerms) { boolean shouldShowRationale; for (String perm : deniedPerms) { shouldShowRationale = Utils.shouldShowRequestPermissionRationale(object, perm); if (!shouldShowRationale) { final Activity activity = Utils.getActivity(object); if (null == activity) { return true; } new AlertDialog.Builder(activity).setMessage(rationale) .setPositiveButton(positiveButton, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", activity.getPackageName(), null); intent.setData(uri); startAppSettingsScreen(object, intent); } }).setNegativeButton(negativeButton, negativeButtonOnClickListener).create().show(); return true; } } return false; }