List of usage examples for android.content.pm PackageManager getApplicationInfo
public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags) throws NameNotFoundException;
From source file:it.scoppelletti.mobilepower.app.HelpActivity.java
/** * Costruisce il testo da visualizzare./*from w w w.jav a 2 s . co m*/ * * @return Testo. */ private String buildText() { String pkgName, value; StringBuilder buf; Bundle data; ApplicationInfo applInfo; PackageManager pkgMgr; pkgName = getPackageName(); myFullPkgName = pkgName; pkgMgr = getPackageManager(); try { applInfo = pkgMgr.getApplicationInfo(pkgName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException ex) { myLogger.error("Failed to get ApplicationInfo.", ex); applInfo = getApplicationInfo(); } buf = new StringBuilder(); buf.append("<h1>"); buf.append(pkgMgr.getApplicationLabel(applInfo)); buf.append("</h1>"); data = applInfo.metaData; if (data != null) { value = data.getString(HelpActivity.METADATA_HELP); if (!StringUtils.isBlank(value)) { buf.append(value); } value = data.getString(AppUtils.METADATA_FULLPACKAGE); if (!StringUtils.isBlank(value)) { myFullPkgName = value; buf.append(getString(R.string.msg_demo)); } } return buf.toString(); }
From source file:com.lillicoder.newsblurry.util.FileLogger.java
/** * Determines if this app is running in debug mode. This value is * automatically set via the build process. * @return <code>true</code> if the app is running in debug mode, * <code>false</code> otherwise. */// w w w . j ava 2 s .co m private boolean isDebugMode() { boolean isDebugMode = false; Context context = this.getContext(); PackageManager packageManager = context.getPackageManager(); try { ApplicationInfo appInfo = packageManager.getApplicationInfo(context.getPackageName(), 0); isDebugMode = (0 != (appInfo.flags &= ApplicationInfo.FLAG_DEBUGGABLE)); } catch (NameNotFoundException e) { Log.e(TAG, String.format(WARNING_FAILED_TO_GET_APPLICATION_INFO, context.getPackageName())); } return isDebugMode; }
From source file:Main.java
public static Drawable getIconFromPackageName(String packageName, Context context) { PackageManager pm = context.getPackageManager(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { try {//from w w w . j av a 2s . co m PackageInfo pi = pm.getPackageInfo(packageName, 0); Context otherAppCtx = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); int displayMetrics[] = { DisplayMetrics.DENSITY_XXXHIGH, DisplayMetrics.DENSITY_XXHIGH, DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_MEDIUM, DisplayMetrics.DENSITY_TV }; for (int displayMetric : displayMetrics) { try { Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon, displayMetric); if (d != null) { return d; } } catch (Resources.NotFoundException e) { } } } catch (Exception e) { // Handle Error here } } ApplicationInfo appInfo = null; try { appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { return null; } return appInfo.loadIcon(pm); }
From source file:com.amazonaws.mobileconnectors.pinpoint.internal.core.system.AndroidAppDetails.java
public AndroidAppDetails(Context context, String appId) { this.applicationContext = context.getApplicationContext(); try {//from w w w. ja v a 2 s. c o m PackageManager packageManager = this.applicationContext.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(this.applicationContext.getPackageName(), 0); ApplicationInfo appInfo = packageManager.getApplicationInfo(packageInfo.packageName, 0); appTitle = (String) packageManager.getApplicationLabel(appInfo); packageName = packageInfo.packageName; versionCode = String.valueOf(packageInfo.versionCode); versionName = packageInfo.versionName; this.appId = appId; } catch (NameNotFoundException e) { log.warn("Unable to get details for package " + this.applicationContext.getPackageName()); appTitle = "Unknown"; packageName = "Unknown"; versionCode = "Unknown"; versionName = "Unknown"; } }
From source file:it.scoppelletti.mobilepower.app.AboutActivity.java
/** * Costruisce il testo da visualizzare./*from w w w.j av a2 s .com*/ * * @return Testo. */ private String buildText() { String pkgName, value; StringBuilder buf; Bundle data; ApplicationInfo applInfo; PackageInfo pkgInfo; PackageManager pkgMgr; pkgName = getPackageName(); pkgMgr = getPackageManager(); try { applInfo = pkgMgr.getApplicationInfo(pkgName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException ex) { myLogger.error("Failed to get ApplicationInfo.", ex); applInfo = getApplicationInfo(); } try { pkgInfo = pkgMgr.getPackageInfo(pkgName, 0); } catch (PackageManager.NameNotFoundException ex) { myLogger.error("Failed to get PackageInfo.", ex); pkgInfo = null; } buf = new StringBuilder(); buf.append("<h1>"); buf.append(pkgMgr.getApplicationLabel(applInfo)); if (pkgInfo != null) { buf.append("<br />"); buf.append(pkgInfo.versionName); } buf.append("</h1>"); data = applInfo.metaData; if (data == null) { return buf.toString(); } value = data.getString(AboutActivity.METADATA_COPYRIGHT); if (!StringUtils.isBlank(value)) { buf.append("<p>"); buf.append(value); buf.append("</p>"); } value = data.getString(AboutActivity.METADATA_LICENSE); if (!StringUtils.isBlank(value)) { buf.append(value); } value = data.getString(AppUtils.METADATA_FULLPACKAGE); if (!StringUtils.isBlank(value)) { buf.append(getString(R.string.msg_demo)); } return buf.toString(); }
From source file:com.afwsamples.testdpc.EnableProfileActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mCheckinState = new CheckInState(this); if (savedInstanceState == null) { if (getIntent().getBooleanExtra(EXTRA_ENABLE_PROFILE_NOW, false)) { mCheckinState.setFirstAccountState(CheckInState.FIRST_ACCOUNT_STATE_READY); ProvisioningUtil.enableProfile(this); } else {/*ww w . ja v a 2 s .c o m*/ // Set up an alarm to enable profile in case we do not receive first account ready // broadcast for whatever reason. FirstAccountReadyBroadcastReceiver.scheduleFirstAccountReadyTimeoutAlarm(this, WAIT_FOR_FIRST_ACCOUNT_READY_TIMEOUT); } } setContentView(R.layout.enable_profile_activity); mSetupWizardLayout = (SetupWizardLayout) findViewById(R.id.setup_wizard_layout); NavigationBar navigationBar = mSetupWizardLayout.getNavigationBar(); navigationBar.getBackButton().setEnabled(false); navigationBar.setNavigationBarListener(this); mFinishButton = navigationBar.getNextButton(); mFinishButton.setText(R.string.finish_button); mCheckInStateReceiver = new CheckInStateReceiver(); // This is just a user friendly shortcut to the policy management screen of this app. ImageView appIcon = (ImageView) findViewById(R.id.app_icon); TextView appLabel = (TextView) findViewById(R.id.app_label); try { PackageManager packageManager = getPackageManager(); ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0 /* Default flags */); appIcon.setImageDrawable(packageManager.getApplicationIcon(applicationInfo)); appLabel.setText(packageManager.getApplicationLabel(applicationInfo)); } catch (PackageManager.NameNotFoundException e) { Log.w("TestDPC", "Couldn't look up our own package?!?!", e); } // Show the user which account now has management, if specified. String addedAccount = getIntent().getStringExtra(LaunchIntentUtil.EXTRA_ACCOUNT_NAME); if (addedAccount != null) { View accountMigrationStatusLayout; if (isAccountMigrated(addedAccount)) { accountMigrationStatusLayout = findViewById(R.id.account_migration_success); } else { accountMigrationStatusLayout = findViewById(R.id.account_migration_fail); } accountMigrationStatusLayout.setVisibility(View.VISIBLE); TextView managedAccountName = (TextView) accountMigrationStatusLayout .findViewById(R.id.managed_account_name); managedAccountName.setText(addedAccount); } }
From source file:org.fdroid.fdroid.privileged.views.UninstallDialogActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String packageName = intent.getStringExtra(Installer.EXTRA_PACKAGE_NAME); PackageManager pm = getPackageManager(); ApplicationInfo appInfo;//from www. j a va 2 s .c om try { //noinspection WrongConstant (lint is actually wrong here!) appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Failed to get ApplicationInfo for uninstalling"); } final boolean isSystem = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; final boolean isUpdate = (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; if (isSystem && !isUpdate) { // Cannot remove system apps unless we're uninstalling updates throw new RuntimeException("Cannot remove system apps unless we're uninstalling updates"); } int messageId; if (isUpdate) { messageId = R.string.uninstall_update_confirm; } else { messageId = R.string.uninstall_confirm; } // hack to get theme applied (which is not automatically applied due to activity's Theme.NoDisplay ContextThemeWrapper theme = new ContextThemeWrapper(this, FDroidApp.getCurThemeResId()); final AlertDialog.Builder builder = new AlertDialog.Builder(theme); builder.setTitle(appInfo.loadLabel(pm)); builder.setIcon(appInfo.loadIcon(pm)); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent data = new Intent(); data.putExtra(Installer.EXTRA_PACKAGE_NAME, packageName); setResult(Activity.RESULT_OK, intent); finish(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setResult(Activity.RESULT_CANCELED); finish(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { setResult(Activity.RESULT_CANCELED); finish(); } }); builder.setMessage(messageId); builder.create().show(); }
From source file:io.bunnyblue.noticedog.app.apps.BaseApp.java
public String getAppName() { try {/* w ww . j a v a 2s . c om*/ PackageManager pm = this.context.getPackageManager(); return pm.getApplicationInfo(getAppId(), 0).loadLabel(pm).toString(); } catch (NameNotFoundException e) { Log.d(TAG, "NameNotFoundException when getting app info for package: " + getAppPackageName()); return getAppPackageName(); } }
From source file:dev.ukanth.ufirewall.broadcast.PackageBroadcast.java
@Override public void onReceive(Context context, Intent intent) { Uri inputUri = Uri.parse(intent.getDataString()); if (!inputUri.getScheme().equals("package")) { Log.d("AFWall+", "Intent scheme was not 'package'"); return;/* w w w . jav a 2 s.c om*/ } if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) { // Ignore application updates final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); if (!replacing) { // Update the Firewall if necessary final int uid = intent.getIntExtra(Intent.EXTRA_UID, -123); Api.applicationRemoved(context, uid); Api.removeCacheLabel(intent.getData().getSchemeSpecificPart(), context); // Force app list reload next time Api.applications = null; } } else if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())) { final boolean updateApp = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); if (updateApp) { // dont do anything //1 check the package already added in firewall } else { // Force app list reload next time Api.applications = null; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean isNotify = prefs.getBoolean("notifyAppInstall", false); if (isNotify && Api.isEnabled(context)) { String added_package = intent.getData().getSchemeSpecificPart(); final PackageManager pkgmanager = context.getPackageManager(); String label = null; try { label = pkgmanager.getApplicationLabel(pkgmanager.getApplicationInfo(added_package, 0)) .toString(); } catch (NameNotFoundException e) { } if (PackageManager.PERMISSION_GRANTED == pkgmanager .checkPermission(Manifest.permission.INTERNET, added_package)) { notifyApp(context, intent, label); } } } } }
From source file:com.oasis.sdk.base.service.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from ww w . j av a 2 s.co m*/ */ private void sendNotification(Bundle data) { Intent clickIntent = new Intent(this, com.oasis.sdk.base.communication.NotificationClickReceiver.class); //???? clickIntent.putExtras(data); int notificationID = (int) (System.currentTimeMillis() / 1000); PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), notificationID, clickIntent, PendingIntent.FLAG_ONE_SHOT); String message = data.getString("message"); String pkName = this.getPackageName(); PackageManager packageManager = this.getPackageManager(); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); ApplicationInfo applicationInfo = null; try { applicationInfo = packageManager.getApplicationInfo(pkName, 0); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); applicationInfo = getApplicationInfo(); } String applicationName = (String) packageManager.getApplicationLabel(applicationInfo); int appicon = applicationInfo.icon; NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(); style.bigText(message); style.setBigContentTitle(applicationName); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(appicon).setContentTitle(applicationName).setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent).setStyle(style); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationID /* ID of notification */, notificationBuilder.build()); }