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:edu.stanford.junction.android.AndroidJunctionMaker.java

/**
 * Finds a pre-existing Junction activity by scanning for a QR code.
 * @param context/*from w  w  w.j  av  a 2 s .co m*/
 */
public static void findActivityByScan(final Activity activity) {
    WaitForInternetCallback callback = new WaitForInternetCallback(activity) {
        @Override
        public void onConnectionFailure() {
            activity.finish();
        }

        @Override
        public void onConnectionSuccess() {
            Intent intent = new Intent("junction.intent.action.join.SCAN");
            intent.putExtra("package", activity.getPackageName());
            IntentLauncher.launch(activity, intent, "edu.stanford.prpl.junction.applaunch",
                    "http://prpl.stanford.edu/android/JunctionAppLauncher.apk", "Activity Director");
        }
    };

    try {
        WaitForInternet.setCallback(callback);
    } catch (SecurityException e) {
        Log.w("junction",
                "Could not check network state. If you'd like this functionality, please add the permission: android.permission.ACCESS_NETWORK_STATE",
                e);
        callback.onConnectionSuccess();
    }
}

From source file:it.mb.whatshare.Dialogs.java

private static String getBuildDate(final Activity activity) {
    String buildDate = "";
    ZipFile zf = null;//ww w  .  j a va2 s  .  co  m
    try {
        ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), 0);
        zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("classes.dex");
        long time = ze.getTime();
        buildDate = SimpleDateFormat.getInstance().format(new java.util.Date(time));

    } catch (Exception e) {
    } finally {
        if (zf != null) {
            try {
                zf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return buildDate;
}

From source file:cn.qqjlbsc.shopseller.utlis.EasyPermissions.java

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;
            }/*w  w  w .j  a va 2  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(object, intent);
                        }
                    }).setNegativeButton(negativeButton, negativeButtonOnClickListener).create();
            dialog.show();

            return true;
        }
    }

    return false;
}

From source file:com.hundsun.yr.mobile.lib.permission.PermissionManager.java

/**
 * OnActivityResult???//from   w w  w.j  a v a2 s  . c o  m
 * {@link PermissionManager#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#onEasyPermissionDenied(int, String[])}
 *
 * @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, String... deniedPerms) {
    boolean shouldShowRationale;
    for (String perm : deniedPerms) {
        shouldShowRationale = PermissionUtils.shouldShowRequestPermissionRationale(object, perm);

        if (!shouldShowRationale) {
            final Activity activity = PermissionUtils.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;
}

From source file:com.garyhu.citypickerdemo.widget.permission.easyPermission.EasyPermission.java

/**
 * OnActivityResult???//w  w w . j ava 2 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#onEasyPermissionDenied(int, String[])}
 *
 * @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, 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;
}

From source file:com.fisher.wxtrend.permission.EasyPermission.java

/**
 * OnActivityResult???/*from   www .ja va2s .  c o m*/
 * {@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 = PermissionUtils.shouldShowRequestPermissionRationale(object, perm);

        if (!shouldShowRationale) {
            final Activity activity = PermissionUtils.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;
}

From source file:net.arvin.pictureselectordemo.EasyPermissions.java

public static boolean checkDeniedPermissionsNeverAskAgain(final Object object, String rationale,
        String positiveButton, String 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;
            }//  www .  j a va  2 s  .com

            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:dentex.youtube.downloader.utils.Utils.java

public static int getSigHash(Activity act) {
    int currentHash = 0;
    try {//from   w w  w . j a  v  a2 s . c o m
        Signature[] sigs = act.getPackageManager().getPackageInfo(act.getPackageName(),
                PackageManager.GET_SIGNATURES).signatures;

        for (Signature sig : sigs) {
            currentHash = sig.hashCode();
            logger("d", "getSigHash: App signature " + currentHash, DEBUG_TAG);
        }
    } catch (NameNotFoundException e) {
        Log.e(DEBUG_TAG, "getSigHash: App signature not found; " + e.getMessage());
    }
    return currentHash;
}

From source file:com.vincent.shaka.util.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.
 *
 * 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.
 * @return {@code true} if user denied at least one permission with the flag NEVER ASK AGAIN.
 *///w  w  w.j a v  a 2 s.c  om
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;
            }

            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);
                            activity.startActivity(intent);
                        }
                    }).setNegativeButton(negativeButton, null).create();
            dialog.show();

            return true;
        }
    }

    return false;
}

From source file:la.xiong.mylibrary.EasyPermissions.java

public static void goSettingsPermissions(final Object object, int dialogType, final int requestCode,
        final int requestCodeForResult, boolean isAppDialog) {
    checkCallingObjectSuitability(object);

    final Activity activity = getActivity(object);
    if (null == activity) {
        return;//from   ww  w. ja  v  a2s  .c om
    }

    //appdialog
    if (isAppDialog == true) {
        if (object instanceof PermissionWithDialogCallbacks) {
            ((PermissionWithDialogCallbacks) object).onDialog(requestCode, dialogType, new DialogCallback() {

                @Override
                public void onGranted() {
                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", activity.getPackageName(), null);
                    intent.setData(uri);
                    startForResult(object, intent, requestCodeForResult);
                }
            });
        }
    } else {
        //TODO easypermissiondialog
    }

}