List of usage examples for android.content Context getPackageName
public abstract String getPackageName();
From source file:Main.java
public static String getVersionName(Context context) { try {/*from w w w .j a v a2 s .c o m*/ return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (Exception e) { e.printStackTrace(); } return "Unknown"; }
From source file:Main.java
public static Uri getUri(Context mContext, int resource_id) { Uri uri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + resource_id); return uri;/*from ww w .ja va 2 s . c om*/ }
From source file:Main.java
static public int getStringResource(Context ctx, String name) { return ctx.getResources().getIdentifier(name, "string", ctx.getPackageName()); }
From source file:Main.java
public static void saveGlobalSetting(Context ctx, String name, Object value) { SharedPreferences setting = ctx.getSharedPreferences(ctx.getPackageName(), 0); setting.edit().putString(name, value.toString()).commit(); }
From source file:Main.java
static public int getLayoutResource(Context ctx, String name) { return ctx.getResources().getIdentifier(name, "layout", ctx.getPackageName()); }
From source file:Main.java
public static int getVersionCode(Context context) { try {/*from w w w . jav a 2s. c o m*/ return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
public static void toScores(Context context) { try {/*w ww .j ava 2 s. c o m*/ Uri uri = Uri.parse("market://details?id=" + context.getPackageName()); Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } catch (Exception e) { } }
From source file:Main.java
private static int getVersionCode(Context context) { try {/*w w w . j ava 2 s .co m*/ return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; } catch (PackageManager.NameNotFoundException e) { return -1; } }
From source file:Main.java
public static boolean hasPermissionInManifest(Context context, String permissionName) { final String packageName = context.getPackageName(); try {/* w ww . j a v a 2s .co m*/ final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); final String[] declaredPermisisons = packageInfo.requestedPermissions; if (declaredPermisisons != null && declaredPermisisons.length > 0) { for (String p : declaredPermisisons) { if (p.equals(permissionName)) { return true; } } } } catch (PackageManager.NameNotFoundException e) { } return false; }
From source file:Main.java
public static String getVersionName(Context context) { try {//from w w w . jav a2 s .c om return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } return "1.0.0"; }