List of usage examples for android.content.pm PackageManager getApplicationLabel
public abstract CharSequence getApplicationLabel(ApplicationInfo info);
From source file:org.sufficientlysecure.keychain.service.remote.AppSettingsFragment.java
private void setPackage(String packageName) { PackageManager pm = getActivity().getApplicationContext().getPackageManager(); // get application name and icon from package manager String appName = null;//ww w.j a v a 2 s . c o m Drawable appIcon = null; try { ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); appName = (String) pm.getApplicationLabel(ai); appIcon = pm.getApplicationIcon(ai); } catch (final NameNotFoundException e) { // fallback appName = packageName; } mAppNameView.setText(appName); mAppIconView.setImageDrawable(appIcon); }
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 {// w w w . ja va 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:com.cmgapps.android.util.CMGAppRater.java
/** * Shows a default {@link AlertDialog}/* w w w . j a v a2 s .c o m*/ * * @param context A Context to show the dialog */ public void show(final Context context) { if (context == null) { throw new IllegalArgumentException("context cannot be null"); } if (Looper.getMainLooper().getThread() != Thread.currentThread()) { throw new RuntimeException("CMGAppRater.show() must be called from main thread"); } if (mDialog != null && mDialog.isShowing()) return; final Editor editor = mPref.edit(); final PackageManager pm = context.getPackageManager(); String appName; try { ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0); appName = (String) pm.getApplicationLabel(ai); } catch (NameNotFoundException e) { LOGE(TAG, "Application name can not be found"); appName = "App"; } mDialog = new AlertDialog.Builder(context).setTitle(R.string.dialog_cmgrate_title) .setMessage(context.getString(R.string.dialog_cmgrate_message, appName)).setCancelable(false) .setIcon(context.getApplicationInfo().icon) .setPositiveButton(context.getString(R.string.dialog_cmgrate_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { editor.putBoolean(APP_RATED, true); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); PreferenceEditorHelper.commit(editor); dialog.dismiss(); } }) .setNegativeButton(R.string.dialog_cmgrate_no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { PreferenceEditorHelper.commit(editor.putBoolean(DECLINED_RATE, true)); dialog.dismiss(); } }).setNeutralButton(R.string.dialog_cmgrate_later, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { PreferenceEditorHelper .commit(editor.putLong(REMIND_LATER_DATE, System.currentTimeMillis())); dialog.dismiss(); } }).show(); PreferenceEditorHelper.commit(editor); }
From source file:org.thoughtcrime.securesms.logsubmit.SubmitLogFragment.java
private static String buildDescription(Context context) { final PackageManager pm = context.getPackageManager(); final StringBuilder builder = new StringBuilder(); builder.append("Time : ").append(System.currentTimeMillis()).append('\n'); builder.append("Device : ").append(Build.MANUFACTURER).append(" ").append(Build.MODEL).append(" (") .append(Build.PRODUCT).append(")\n"); builder.append("Android : ").append(VERSION.RELEASE).append(" (").append(VERSION.INCREMENTAL).append(", ") .append(Build.DISPLAY).append(")\n"); builder.append("ABIs : ").append(TextUtils.join(", ", getSupportedAbis())).append("\n"); builder.append("Memory : ").append(getMemoryUsage(context)).append("\n"); builder.append("Memclass: ").append(getMemoryClass(context)).append("\n"); builder.append("OS Host : ").append(Build.HOST).append("\n"); builder.append("App : "); try {/*www. j a v a2s . c o m*/ builder.append(pm.getApplicationLabel(pm.getApplicationInfo(context.getPackageName(), 0))).append(" ") .append(pm.getPackageInfo(context.getPackageName(), 0).versionName).append("\n"); } catch (PackageManager.NameNotFoundException nnfe) { builder.append("Unknown\n"); } return builder.toString(); }
From source file:it.ms.theing.loquitur.functions.IntentInterface.java
/** * List All Apps//from w ww . jav a2s . com * @return * A string containing the json array of json object : * Structure : * [ { name:<name> , package:<package> }, .... ] */ @JavascriptInterface public String listApps() { try { JSONArray ja = new JSONArray(); PackageManager packman; packman = context.getPackageManager(); List<PackageInfo> pak = packman.getInstalledPackages(0); for (PackageInfo pi : pak) { String name = (String) packman.getApplicationLabel(pi.applicationInfo); String pk = (String) pi.packageName; JSONObject jo = new JSONObject(); try { jo.put("name", name); jo.put("package", pk); ja.put(jo); } catch (JSONException e) { } } return ja.toString(); } catch (Exception e) { Utils.safe(e); } return "[ ]"; }
From source file:it.ms.theing.loquitur.functions.IntentInterface.java
/** * Find a similar app//from w ww. j av a 2 s .c o m * @param compare * The name of the app to match with the list * @param minscore * The minimum accuracy * @return * The best matching */ @JavascriptInterface public String matchApp(String compare, float minscore) { try { PackageManager packman; packman = context.getPackageManager(); List<PackageInfo> pak = packman.getInstalledPackages(0); PackageInfo spi = null; for (PackageInfo pi : pak) { String name = (String) packman.getApplicationLabel(pi.applicationInfo); float score = Utils.match(name, compare); if (score > minscore) { minscore = score; spi = pi; } } if (spi == null) return ""; String name = (String) packman.getApplicationLabel(spi.applicationInfo); String pk = (String) spi.packageName; JSONObject jo = new JSONObject(); jo.put("name", name); jo.put("package", pk); return jo.toString(); } catch (Exception e) { Utils.safe(e); } return ""; }
From source file:de.schildbach.wallet.ui.ChannelRequestActivity.java
private void initWithBinder() { // Figure out the caller of this activity. PackageManager packageManager = getApplicationContext().getPackageManager(); final String callingPackage = getCallingPackage(); try {//w w w .j a va2s .c om ApplicationInfo appInfo = packageManager.getApplicationInfo(callingPackage, 0); requestingApp = packageManager.getApplicationLabel(appInfo); } catch (PackageManager.NameNotFoundException e) { // Fall through. } if (requestingApp == null) requestingApp = "unknown"; // TODO: Show the user how much the app can still spend, maybe even how much it has spent long amountLeft = service.getAppValueRemaining(callingPackage); appSpecifiedMinValue = appSpecifiedMinValue - amountLeft; requestedValueStr = GenericUtils.formatValue(BigInteger.valueOf(appSpecifiedMinValue), Constants.BTC_MAX_PRECISION) + " " + Constants.CURRENCY_CODE_BITCOIN; final String intro = getString(R.string.channel_request_intro, requestingApp, requestedValueStr, ""); final TextView label = (TextView) findViewById(R.id.channel_request_intro_text); label.setText(intro); btcAmountView.setAmount(BigInteger.valueOf(appSpecifiedMinValue), true); acceptButton.setEnabled(true); }
From source file:it.scoppelletti.mobilepower.app.HelpActivity.java
/** * Costruisce il testo da visualizzare.//from w ww . ja v a2 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.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 .ja v a 2 s. c o 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()); }
From source file:de.treichels.hott.ui.android.MdlViewerActivity.java
/** * Called when the activity is first created. * * @param savedInstanceState//from w w w. j av a 2s . co m * If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in * onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b> */ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); // set the version of the application from the manifest try { final PackageManager pm = getPackageManager(); final CharSequence label = pm.getApplicationLabel(getApplicationInfo()); final PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0); final String versionName = packageInfo.versionName; if (label != null && label.length() > 0 && versionName != null && versionName.length() > 0) { setTitle(label + " " + versionName); } } catch (final NameNotFoundException e) { // ignore } setContentView(R.layout.main); // temporary file to store html try { loadUrl = getFileStreamPath(CACHE_FILE_NAME).toURI().toURL().toString(); } catch (final MalformedURLException e) { throw new RuntimeException(e); } progressBar = (ProgressBar) findViewById(R.id.progressBar); progressBar.setVisibility(View.INVISIBLE); webView = (WebView) findViewById(R.id.webwiew); webView.getSettings().setBuiltInZoomControls(true); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawer = (ListView) findViewById(R.id.drawer); drawer.setOnItemClickListener(this); final Intent intent = getIntent(); if (intent != null && intent.getAction() == Intent.ACTION_VIEW) { // activity was started via an intent updateUI(intent.getData()); } else if (savedInstanceState != null) { // restore from saved state if (savedInstanceState.containsKey(MODEL_NAME)) { modelName = savedInstanceState.getString(MODEL_NAME); } if (savedInstanceState.containsKey(MODEL_TYPE)) { modelType = ModelType.valueOf(savedInstanceState.getString(MODEL_TYPE)); } if (savedInstanceState.containsKey(TRANSMITTER_TYPE)) { transmitterType = TransmitterType.valueOf(savedInstanceState.getString(TRANSMITTER_TYPE)); } updateUI(); // } else { // fall back to load from file // performFileSearch(); } }