List of usage examples for android.app Activity getPackageName
@Override
public String getPackageName()
From source file:com.lvbo.template.common.Utils.PermissionUtils.java
/** * ??//from w w w .j a v a 2 s . co m * * @param cxt * @param req * @return */ @TargetApi(23) public static boolean checkSettingAlertPermission(Object cxt, int req) { if (cxt instanceof Activity) { Activity activity = (Activity) cxt; if (!Settings.canDrawOverlays(activity.getBaseContext())) { Log.i(TAG, "Setting not permission"); Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + activity.getPackageName())); activity.startActivityForResult(intent, req); return false; } } else if (cxt instanceof Fragment) { Fragment fragment = (Fragment) cxt; if (!Settings.canDrawOverlays(fragment.getActivity())) { Log.i(TAG, "Setting not permission"); Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + fragment.getActivity().getPackageName())); fragment.startActivityForResult(intent, req); Context c; return false; } } else { throw new RuntimeException("cxt is net a activity or fragment"); } return true; }
From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java
@SuppressWarnings("nls") private static File getTempFile(Activity activity) { try {/*from w w w . jav a 2s . co m*/ String storageState = Environment.getExternalStorageState(); if (storageState.equals(Environment.MEDIA_MOUNTED)) { String path = Environment.getExternalStorageDirectory().getName() + File.separatorChar + "Android/data/" + activity.getPackageName() + "/files/"; File photoFile = File.createTempFile("comment_pic_" + DateUtilities.now(), ".jpg", new File(path)); return photoFile; } } catch (IOException e) { return null; } return null; }
From source file:net.canking.permissiondemo.PermissionUtils.java
/** * WRITE_SETTINGS ??/* www .ja v a 2 s. c o m*/ * @param cxt * @param req * @return */ @TargetApi(23) public static boolean checkSettingSystemPermission(Object cxt, int req) { if (cxt instanceof Activity) { Activity activity = (Activity) cxt; if (!Settings.System.canWrite(activity)) { Log.i(TAG, "Setting not permission"); Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + activity.getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivityForResult(intent, req); return false; } } else if (cxt instanceof Fragment) { Fragment fragment = (Fragment) cxt; if (!Settings.System.canWrite(fragment.getContext())) { Log.i(TAG, "Setting not permission"); Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS); intent.setData(Uri.parse("package:" + fragment.getContext().getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); fragment.startActivityForResult(intent, req); return false; } } else { throw new RuntimeException("cxt is net a activity or fragment"); } return true; }
From source file:com.repkap11.repcast.utils.Utils.java
public static void showUpdateDialogIfNecessary(Activity activity) { try {/*from w ww. j a va 2 s. c o m*/ SharedPreferences prefs = activity.getSharedPreferences("CHANGELOG", Context.MODE_PRIVATE); int currentVersionCode = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionCode; boolean hasShownPrevious = prefs.getBoolean("has-shown-prefs-" + (currentVersionCode - 1), false); boolean hasShownCurrent = prefs.getBoolean("has-shown-prefs-" + currentVersionCode, false); //Log.e(TAG, "hasShownPrevious:" + hasShownPrevious + " hasShownCurrent:" + hasShownCurrent); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("has-shown-prefs-" + currentVersionCode, true); editor.putBoolean("has-shown-prefs-" + (currentVersionCode - 1), true); if ((hasShownPrevious && !hasShownCurrent)) { AlertDialog d = new AlertDialog.Builder(activity) .setTitle("Changelog: App Version " + currentVersionCode) .setMessage(activity.getResources().getString(R.string.changelog_message)) .setCancelable(false).setNegativeButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); //DisplayMetrics metrics = activity.getResources().getDisplayMetrics(); //int width = metrics.widthPixels; //int height = metrics.heightPixels; //Log.e(TAG, "Width:" + width + " Height:" + height); //d.getWindow().setLayout(width,height); } editor.apply(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Start the activity./*from w ww . j a v a 2 s . co m*/ * * @param activity The activity. * @param clz The activity class. * @param requestCode if >= 0, this code will be returned in * onActivityResult() when the activity exits. * @param enterAnim A resource ID of the animation resource to use for the * incoming activity. * @param exitAnim A resource ID of the animation resource to use for the * outgoing activity. */ public static void startActivityForResult(@NonNull final Activity activity, @NonNull final Class<? extends Activity> clz, final int requestCode, @AnimRes final int enterAnim, @AnimRes final int exitAnim) { startActivityForResult(activity, null, activity.getPackageName(), clz.getName(), requestCode, getOptionsBundle(activity, enterAnim, exitAnim)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { activity.overridePendingTransition(enterAnim, exitAnim); } }
From source file:Main.java
/** * Start the activity./*from w w w . j a v a 2 s . co m*/ * * @param extras The Bundle of extras to add to this intent. * @param activity The activity. * @param clz The activity class. * @param requestCode if >= 0, this code will be returned in * onActivityResult() when the activity exits. * @param enterAnim A resource ID of the animation resource to use for the * incoming activity. * @param exitAnim A resource ID of the animation resource to use for the * outgoing activity. */ public static void startActivityForResult(@NonNull final Bundle extras, @NonNull final Activity activity, @NonNull final Class<? extends Activity> clz, final int requestCode, @AnimRes final int enterAnim, @AnimRes final int exitAnim) { startActivityForResult(activity, extras, activity.getPackageName(), clz.getName(), requestCode, getOptionsBundle(activity, enterAnim, exitAnim)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { activity.overridePendingTransition(enterAnim, exitAnim); } }
From source file:Main.java
/** * Open an URL in a message./*from w w w. j av a2 s. c o m*/ * * This is intended to mirror the operation of the original * (see android.webkit.CallbackProxy) with one addition of intent flags * "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET". This improves behavior when sublaunching * other apps via embedded URI's. * * We also use this hook to catch "mailto:" links and handle them locally. * * @param activity parent activity * @param url URL to open * @param senderAccountId if the URL is mailto:, we use this account as the sender. * TODO When MessageCompose implements the account selector, this won't be necessary. * Pass {@link Account#NO_ACCOUNT} to use the default account. * @return true if the URI has successfully been opened. */ public static boolean openUrlInMessage(Activity activity, String url, long senderAccountId) { // hijack mailto: uri's and handle locally //*** //if (url != null && url.toLowerCase().startsWith("mailto:")) { // return MessageCompose.actionCompose(activity, url, senderAccountId); //} // Handle most uri's via intent launch boolean result = false; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName()); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); try { activity.startActivity(intent); result = true; } catch (ActivityNotFoundException ex) { // No applications can handle it. Ignore. } return result; }
From source file:com.vivekpanyam.evolve.Utils.java
/** * Set the ClassLoader for the running application * * @param a An activity in the currently running application * @param classLoader The ClassLoader used to load the new DEX file *//* ww w . jav a2 s . c o m*/ public static void setClassLoader(Activity a, ClassLoader classLoader) { try { Field mMainThread = getField(Activity.class, "mMainThread"); Object mainThread = mMainThread.get(a); Class<?> threadClass = mainThread.getClass(); Field mPackages = getField(threadClass, "mPackages"); HashMap<String, ?> map = (HashMap<String, ?>) mPackages.get(mainThread); WeakReference<?> ref = (WeakReference<?>) map.get(a.getPackageName()); Object apk = ref.get(); Class<?> apkClass = apk.getClass(); Field mClassLoader = getField(apkClass, "mClassLoader"); mClassLoader.set(apk, classLoader); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.facebook.unity.FB.java
/** * Provides the key hash to solve the openSSL issue with Amazon * @return key hash/*from w ww .ja v a 2 s .co m*/ */ @TargetApi(Build.VERSION_CODES.FROYO) public static String getKeyHash() { try { // In some cases the unity activity may not exist. This can happen when we are // completing a login and unity activity was killed in the background. In this // situation it's not necessary to send back the keyhash since the app will overwrite // the value with the value they get during the init call and the unity activity // wil be created by the time init is called. Activity activity = getUnityActivity(); if (activity == null) { return ""; } PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT); Log.d(TAG, "KeyHash: " + keyHash); return keyHash; } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } return ""; }
From source file:com.mobivery.greent.MVYBatteryManagerActivityFragment.java
public static boolean isApplicationBroughtToBackground(final Activity activity) { ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1); // Check the top Activity against the list of Activities contained in the Application's package. if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; try {/*from w w w .ja va2 s . co m*/ PackageInfo pi = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES); for (ActivityInfo activityInfo : pi.activities) { if (topActivity.getClassName().equals(activityInfo.name)) return false; } } catch (PackageManager.NameNotFoundException e) { return false; // Never happens. } } return true; }