PackageInfo pInfo; try { pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA); if ( prefs.getLong( "lastRunVersionCode", 0) < pInfo.versionCode ) { // TODO: Handle your first-run situation here Editor editor = prefs.edit(); editor.putLong("lastRunVersionCode", pInfo.versionCode); editor.commit(); } } catch (NameNotFoundException e) { // TODO Something pretty serious went wrong if you got here... e.printStackTrace(); }
try { ApplicationInfo app = this.getPackageManager().getApplicationInfo("com.example.name", 0); Drawable icon = packageManager.getApplicationIcon(app); String name = packageManager.getApplicationLabel(app); return icon; } catch (NameNotFoundException e) { Toast toast = Toast.makeText(this, "error in getting icon", Toast.LENGTH_SHORT); toast.show(); e.printStackTrace(); }
// Define the debug signature hash (Android default debug cert). Code from sigs[i].hashCode() protected final static int DEBUG_SIGNATURE_HASH = <your hash value>; // Checks if this apk was built using the debug certificate // Used e.g. for Google Maps API key determination (from: http://whereblogger.klaki.net/2009/10/choosing-android-maps-api-key-at-run.html) public static Boolean isDebugBuild(Context context) { if (_isDebugBuild == null) { try { _isDebugBuild = false; Signature [] sigs = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES).signatures; for (int i = 0; i < sigs.length; i++) { if (sigs[i].hashCode() == DEBUG_SIGNATURE_HASH) { Log.d(TAG, "This is a debug build!"); _isDebugBuild = true; break; } } } catch (NameNotFoundException e) { e.printStackTrace(); } } return _isDebugBuild; }
PackageManager pm = getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo applicationInfo : packages) { Log.d("test", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName); try { PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS); //Get Permissions String[] requestedPermissions = packageInfo.requestedPermissions; if(requestedPermissions != null) { for (int i = 0; i < requestedPermissions.length; i++) { Log.d("test", requestedPermissions[i]); } } } catch (NameNotFoundException e) { e.printStackTrace(); } }
newInfo.setP(p); } catch (NameNotFoundException e) { e.printStackTrace(); return null;
try { PackageManager manager = context.getPackageManager(); PackageInfo info = manager.getPackageInfo("org.moo.android.myApp", 0); int code = info.versionCode; String name = info.versionName; // Compare with values on the server to see if there is a new version } catch(NameNotFoundException nnf) { nnf.printStackTrace(); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about_layout); String versionName = ""; try { PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); versionName = pinfo.versionName; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } TextView aboutTextView = (TextView) findViewById(R.id.about_text_view); aboutText = Html.fromHtml("<h1>Your App Name, Version " + versionName + "</h1>" + getString(R.string.about_text)); aboutTextView.setText(aboutText); }
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0); for (Object obj : pkgAppsList) { ResolveInfo resolveInfo = (ResolveInfo) obj; PackageInfo packageInfo = null; try { packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String[] requestedPermissions = packageInfo.requestedPermissions; }
PackageManager packageManager = activity.getPackageManager(); try { ActivityInfo info = packageManager.getActivityInfo(activity.getComponentName(), 0); Log.e("app", "Activity name:" + info.name); } catch (NameNotFoundException e) { e.printStackTrace(); }
final PackageManager packageManager = getPackageManager(); try { final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0); if ("com.android.vending".equals(packageManager.getInstallerPackageName(applicationInfo.packageName))) { // App was installed by Play Store } } catch (final NameNotFoundException e) { e.printStackTrace(); }
final String packName = "com.example2.app"; String mDrawableName = "app_icon"; try { PackageManager manager = getPackageManager(); Resources mApk1Resources = manager.getResourcesForApplication(packName); int mDrawableResID = mApk1Resources.getIdentifier(mDrawableName, "drawable",packName); Drawable myDrawable = mApk1Resources.getDrawable( mDrawableResID ); if( myDrawable != null ) TEST.setBackgroundDrawable(myDrawable ); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }
private boolean checkAuthorised(){ PackageManager pm = getPackageManager(); try { for (Signature sig : pm.getPackageInfo(pm.getNameForUid(getCallingUid()), PackageManager.GET_SIGNATURES).signatures){ LogUtils.logD("Signature: " + sig.toCharsString()); if (Security.trustedSignatures.get(sig.toCharsString()) != null) { return true; } } } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } LogUtils.logD("Couldn't find signature in list of trusted keys! Possibilities:"); for(String sigString : Security.trustedSignatures.keySet()){ LogUtils.logD(sigString); } /* Crash the calling application if it doesn't catch */ throw new SecurityException(); }
int version = 1; try { version = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); } if(version > ...) { //do something }
for (ResolveInfo resolveInfo : appList ) { try { ApplicationInfo ai =context.getPackageManager().getApplicationInfo(resolveInfo.activityInfo.packageName, 0); // your code here } catch (NameNotFoundException e) { e.printStackTrace(); } }
try { Context c = createPackageContext(com.app.first, MODE_PRIVATE); SharedPreferences prefs = c.getSharedPreferences( "com.app.first_preferences", MODE_PRIVATE); } catch (NameNotFoundException e) { e.printStackTrace(); }
try { final ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA); final String version = (String)ai.metaData.get("com.example.version"); System.out.println("version: " + version); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }
EditText ET1 = (EditText) findViewById(R.id.editText1); PackageInfo pinfo; try { pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); String versionName = pinfo.versionName; ET1.setText(versionName); //ET2.setText(versionNumber); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }
// See if we're a debug or a release build try { PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES); if (packageInfo.signatures.length>0) { String signature = new String(packageInfo.signatures[0].toByteArray()); isReleaseBuild = !signature.contains("Android Debug"); } } catch (NameNotFoundException e1) { e1.printStackTrace(); }
PackageManager pkManager = activity.getPackageManager(); try { PackageInfo pkgInfo = pkManager.getPackageInfo("com.twitter.android", 0); String getPkgInfo = pkgInfo.toString(); if (getPkgInfo.equals("com.twitter.android")) { // APP NOT INSTALLED } } catch (NameNotFoundException e) { e.printStackTrace(); // APP NOT INSTALLED }
PackageManager pm = getPackageManager(); try { Resources resources = pm.getResourcesForApplication("com.example.app"); int id = resources.getIdentifier("ic_launcher", "drawable", "com.example.app"); Drawable d = resources.getDrawable(id) } catch (NameNotFoundException e) { e.printStackTrace(); }