Example usage for android.app Activity getPackageName

List of usage examples for android.app Activity getPackageName

Introduction

In this page you can find the example usage for android.app Activity getPackageName.

Prototype

@Override
    public String getPackageName() 

Source Link

Usage

From source file:com.are.photophone.utils.permissionutils.EasyPermissions.java

/**
 * 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>/*from w  ww.j  a  v a  2s.c  om*/
 * NOTE: use of this method is optional, should be called from
 * {@link PermissionCallbacks#onPermissionsDenied(int, List)}
 *
 * @param object                        the calling Activity or Fragment.
 * @param deniedPerms                   the set of denied permissions.
 * @param negativeButtonOnClickListener negative button on click listener. If the
 *                                      user click the negative button, then this listener will
 *                                      be called. Pass null if you don't want to handle it.
 * @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 = shouldShowRequestPermissionRationale(object, perm);
        if (!shouldShowRationale) {
            final Activity activity = getActivity(object);
            if (null == activity) {
                return true;
            }

            AlertDialog dialog = new AlertDialog.Builder(activity).setIcon(R.drawable.ic_alert)
                    .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();
            dialog.show();

            return true;
        }
    }

    return false;
}

From source file:com.base.utils.permission.EasyPermissions.java

/**
 * 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/>/*from w  w w  . j ava  2s .  co m*/
 * NOTE: use of this method is optional, should be called from
 * {@link PermissionCallbacks#onPermissionsDenied(int, List)}
 *
 * @param object                        the calling Activity or Fragment.
 * @param deniedPerms                   the set of denied permissions.
 * @param negativeButtonOnClickListener negative button on click listener. If the
 *                                      user click the negative button, then this listener will
 *                                      be called. Pass null if you don't want to handle it.
 * @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 = shouldShowRequestPermissionRationale(object, perm);
        if (shouldShowRationale) {
            final Activity activity = getActivity(object);
            if (null == activity) {
                return true;
            }

            AlertDialog dialog = 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();
            dialog.show();
            return true;
        }
    }
    return false;
}

From source file:com.mobicage.rogerthat.util.ui.UIUtils.java

public static boolean isRogerthatTopActivity() {
    final Activity topActivity = UIUtils.getTopActivity();
    if (topActivity == null)
        return false;
    return App.getContext().getPackageName().equals(topActivity.getPackageName());
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static void settingPermission(@NonNull Activity activity) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(activity)) {
        MaterialDialog.Builder builder = new MaterialDialog.Builder(activity).title(R.string.permissions_title)
                .content(R.string.writesetting).positiveText(R.string.btn_continue)
                .negativeText(R.string.btn_cancel).autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override/*from   w w w . j a  va2 s.  c o m*/
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
                                    Uri.fromParts("package", activity.getPackageName(), null));
                            if (Helper.isActivityPresent(activity, intent)) {
                                activity.startActivityForResult(intent, WRITESETTINGS);
                            } else {
                                Toast.makeText(activity, "No app found to handle settings write permission",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Toast.makeText(activity, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT)
                                .show();
                        dialog.dismiss();
                    }
                }).neutralText("Never show again").onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Extras.getInstance().setSettings(true);
                        dialog.dismiss();
                    }
                });
        if (activity.hasWindowFocus() || !activity.isFinishing()) {
            builder.show();
        }
    }
}

From source file:com.diusrex.update.Update.java

public boolean execute(String className, JSONArray args, CallbackContext callbackContext) throws JSONException {
    Activity activity = this.cordova.getActivity();
    final String appPackageName = activity.getPackageName();
    try {/*w w w .  j  a  va 2  s . c  o m*/
        activity.startActivity(
                new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
    } catch (android.content.ActivityNotFoundException anfe) {
        activity.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
    }

    boolean quitApp = args.getBoolean(0);
    if (quitApp) {
        activity.finish();
    }

    return true;
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static void widgetPermission(@NonNull Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(activity)) {
        MaterialDialog.Builder dialog = new MaterialDialog.Builder(activity).title(R.string.permissions_title)
                .content(R.string.draw_over_permissions_message).positiveText(R.string.btn_continue)
                .negativeText(R.string.btn_cancel).autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override//from   w ww .j a  va 2  s  .  co  m
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                                    Uri.fromParts("package", activity.getPackageName(), null));
                            if (Helper.isActivityPresent(activity, intent)) {
                                activity.startActivityForResult(intent, OVERLAY_REQ);
                            } else {
                                Toast.makeText(activity,
                                        "No app found to handle floating widget enable permission",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Toast.makeText(activity, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT)
                                .show();
                        dialog.dismiss();
                    }
                }).neutralText("Never show again").onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Extras.getInstance().setWidgetTrack(true);
                        dialog.dismiss();
                    }
                });
        if (activity.hasWindowFocus() || !activity.isFinishing()) {
            dialog.show();
        }
    }
}

From source file:com.xiaodu.permission.util2.ESPermission.java

public static boolean checkDeniedPermissionsNeverAskAgain(final Activity activity, String rationale,
        @StringRes int positiveButton, @StringRes int negativeButton, List<String> deniedPerms) {
    boolean shouldShowRationale;
    for (String perm : deniedPerms) {
        shouldShowRationale = shouldShowRequestPermissionRationale(activity, perm);
        if (!shouldShowRationale) {
            if (null == getActivity(activity)) {
                return true;
            }/*  w  w  w . j a va2 s. c o m*/

            AlertDialog dialog = 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(activity, intent);
                        }
                    }).setNegativeButton(negativeButton, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).create();
            dialog.show();

            return true;
        }
    }

    return false;
}

From source file:com.albedinsky.android.support.intent.PlayIntent.java

/**
 * Creates a new instance of PlayIntent for the given <var>activity</var> context.
 * See {@link com.albedinsky.android.support.intent.BaseIntent#BaseIntent(Activity)}
 * for additional info.//from www  .j  a  va 2s . c o m
 */
public PlayIntent(@NonNull Activity activity) {
    super(activity);
    this.mPackageName = activity.getPackageName();
}

From source file:com.unlockdisk.android.opengl.MainGLActivity.java

private int findSoundId(Activity activity, String variable) {
    try {//w  w  w  .j  a  v a 2s.  co m
        String idClass = activity.getPackageName() + ".R$raw";
        Class clazz = Class.forName(idClass);
        Field field = clazz.getField(variable);

        return field.getInt(clazz);
    } catch (Exception e) {
        return -1;
    }
}

From source file:io.selendroid.server.model.internal.execute_native.GetL10nKeyTranslation.java

private String getLocalizedString(String l10nKey) {
    Activity currentActivity = serverInstrumentation.getCurrentActivity();
    int resourceId = currentActivity.getResources().getIdentifier(l10nKey, "string",
            currentActivity.getPackageName());
    try {/*from   www.  j a v  a 2s. c o  m*/
        return currentActivity.getResources().getString(resourceId);
    } catch (Resources.NotFoundException e) {
        return "";
    }
}