List of usage examples for android.content.pm PackageManager getPackageInfo
public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags) throws NameNotFoundException;
From source file:uk.org.openseizuredetector.OsdUtil.java
private boolean isPackageInstalled(String packagename) { PackageManager pm = mContext.getPackageManager(); try {//from w ww. java 2 s . c o m pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES); //showToast("found "+packagename); return true; } catch (PackageManager.NameNotFoundException e) { //showToast(packagename + " not found"); return false; } }
From source file:com.activiti.android.app.fragments.integration.alfresco.AlfrescoIntegrationFragment.java
private PackageInfo getAlfrescoInfo(Context context) { PackageManager pm = context.getPackageManager(); try {//from w w w. j ava2s .c o m return pm.getPackageInfo(AlfrescoIntegrator.ALFRESCO_APP_PACKAGE, 0); } catch (PackageManager.NameNotFoundException e) { return null; } }
From source file:com.artemchep.horario.ui.dialogs.FeedbackDialog.java
/** * Creates the name of the email.//from w ww. ja va2s . c om * * @param type one of the following types: * 0 - issue * 1 - suggestion * 2 - other * @return the name of the email. */ @NonNull private CharSequence createTitle(@NonNull Context context, int type) { CharSequence osVersion = Device.API_VERSION_NAME_SHORT; CharSequence msgTypeStr; switch (type) { case TYPE_ISSUE: msgTypeStr = "issue"; break; case TYPE_SUGGESTION: msgTypeStr = "suggestion"; break; case TYPE_OTHER: default: msgTypeStr = "other"; break; } // Get version name String versionName; try { PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); PackageInfo info = pm.getPackageInfo(packageName, 0); versionName = info.versionName; } catch (PackageManager.NameNotFoundException e) { versionName = "N/A"; } return String.format("%s v%s: %s, %s", getString(R.string.app_name), versionName, osVersion, msgTypeStr); }
From source file:com.cleanwiz.applock.ui.activity.SplashActivity.java
public String getApplicationVersion() { PackageManager packageManager = getPackageManager(); PackageInfo packageInfo;/*from w ww. j a v a2s. com*/ try { packageInfo = packageManager.getPackageInfo(getPackageName(), 0); return packageInfo.versionName; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; }
From source file:de.quist.app.errorreporter.ExceptionReportService.java
private void sendReport(Intent intent) throws UnsupportedEncodingException, NameNotFoundException { Log.v(TAG, "Got request to report error: " + intent.toString()); Uri server = getTargetUrl();/* w w w. j a v a 2 s .c om*/ boolean isManualReport = intent.getBooleanExtra(EXTRA_MANUAL_REPORT, false); boolean isReportOnFroyo = isReportOnFroyo(); boolean isFroyoOrAbove = isFroyoOrAbove(); if (isFroyoOrAbove && !isManualReport && !isReportOnFroyo) { // We don't send automatic reports on froyo or above Log.d(TAG, "Don't send automatic report on froyo"); return; } Set<String> fieldsToSend = getFieldsToSend(); String stacktrace = intent.getStringExtra(EXTRA_STACK_TRACE); String exception = intent.getStringExtra(EXTRA_EXCEPTION_CLASS); String message = intent.getStringExtra(EXTRA_MESSAGE); long availableMemory = intent.getLongExtra(EXTRA_AVAILABLE_MEMORY, -1l); long totalMemory = intent.getLongExtra(EXTRA_TOTAL_MEMORY, -1l); String dateTime = intent.getStringExtra(EXTRA_EXCEPTION_TIME); String threadName = intent.getStringExtra(EXTRA_THREAD_NAME); String extraMessage = intent.getStringExtra(EXTRA_EXTRA_MESSAGE); List<NameValuePair> params = new ArrayList<NameValuePair>(); addNameValuePair(params, fieldsToSend, "exStackTrace", stacktrace); addNameValuePair(params, fieldsToSend, "exClass", exception); addNameValuePair(params, fieldsToSend, "exDateTime", dateTime); addNameValuePair(params, fieldsToSend, "exMessage", message); addNameValuePair(params, fieldsToSend, "exThreadName", threadName); if (extraMessage != null) addNameValuePair(params, fieldsToSend, "extraMessage", extraMessage); if (availableMemory >= 0) addNameValuePair(params, fieldsToSend, "devAvailableMemory", availableMemory + ""); if (totalMemory >= 0) addNameValuePair(params, fieldsToSend, "devTotalMemory", totalMemory + ""); PackageManager pm = getPackageManager(); try { PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0); addNameValuePair(params, fieldsToSend, "appVersionCode", packageInfo.versionCode + ""); addNameValuePair(params, fieldsToSend, "appVersionName", packageInfo.versionName); addNameValuePair(params, fieldsToSend, "appPackageName", packageInfo.packageName); } catch (NameNotFoundException e) { } addNameValuePair(params, fieldsToSend, "devModel", android.os.Build.MODEL); addNameValuePair(params, fieldsToSend, "devSdk", android.os.Build.VERSION.SDK); addNameValuePair(params, fieldsToSend, "devReleaseVersion", android.os.Build.VERSION.RELEASE); HttpClient httpClient = new DefaultHttpClient(); HttpPost post = new HttpPost(server.toString()); post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); Log.d(TAG, "Created post request"); try { httpClient.execute(post); Log.v(TAG, "Reported error: " + intent.toString()); } catch (ClientProtocolException e) { // Ignore this kind of error Log.e(TAG, "Error while sending an error report", e); } catch (SSLException e) { Log.e(TAG, "Error while sending an error report", e); } catch (IOException e) { if (e instanceof SocketException && e.getMessage().contains("Permission denied")) { Log.e(TAG, "You don't have internet permission", e); } else { int maximumRetryCount = getMaximumRetryCount(); int maximumExponent = getMaximumBackoffExponent(); // Retry at a later point in time AlarmManager alarmMgr = (AlarmManager) getSystemService(ALARM_SERVICE); int exponent = intent.getIntExtra(EXTRA_CURRENT_RETRY_COUNT, 0); intent.putExtra(EXTRA_CURRENT_RETRY_COUNT, exponent + 1); PendingIntent operation = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); if (exponent >= maximumRetryCount) { // Discard error Log.w(TAG, "Error report reached the maximum retry count and will be discarded.\nStacktrace:\n" + stacktrace); return; } if (exponent > maximumExponent) { exponent = maximumExponent; } long backoff = (1 << exponent) * 1000; // backoff in ms alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + backoff, operation); } } }
From source file:io.teak.sdk.AppConfiguration.java
public AppConfiguration(@NonNull Context context) { // Teak App Id {/* ww w . j ava 2s.co m*/ this.appId = Helpers.getStringResourceByName(TEAK_APP_ID, context); if (this.appId == null) { throw new RuntimeException("Failed to find R.string." + TEAK_APP_ID); } } // Teak API Key { this.apiKey = Helpers.getStringResourceByName(TEAK_API_KEY, context); if (this.apiKey == null) { throw new RuntimeException("Failed to find R.string." + TEAK_API_KEY); } } // Push Sender Id { // TODO: Check ADM vs GCM this.pushSenderId = Helpers.getStringResourceByName(TEAK_GCM_SENDER_ID, context); if (this.pushSenderId == null && Teak.isDebug) { Log.d(LOG_TAG, "R.string." + TEAK_GCM_SENDER_ID + " not present, push notifications disabled."); } } // Package Id { this.bundleId = context.getPackageName(); if (this.bundleId == null) { throw new RuntimeException("Failed to get Bundle Id."); } } PackageManager packageManager = context.getPackageManager(); if (packageManager == null) { throw new RuntimeException("Unable to get Package Manager."); } // App Version { int tempAppVersion = 0; try { tempAppVersion = packageManager.getPackageInfo(this.bundleId, 0).versionCode; } catch (Exception e) { Log.e(LOG_TAG, "Error getting App Version: " + Log.getStackTraceString(e)); } finally { this.appVersion = tempAppVersion; } } // Get the installer package { this.installerPackage = packageManager.getInstallerPackageName(this.bundleId); if (this.installerPackage == null) { Log.e(LOG_TAG, "Installer package (Store) is null, purchase tracking disabled."); } } // Tell the Raven service about the app id try { Intent intent = new Intent(context, RavenService.class); intent.putExtra("appId", this.appId); ComponentName componentName = context.startService(intent); if (componentName == null) { Log.e(LOG_TAG, "Unable to communicate with exception reporting service. Please add:\n\t<service android:name=\"io.teak.sdk.service.RavenService\" android:process=\":teak.raven\" android:exported=\"false\"/>\nTo the <application> section of your AndroidManifest.xml"); } else if (Teak.isDebug) { Log.d(LOG_TAG, "Communication with exception reporting service established: " + componentName.toString()); } } catch (Exception e) { Log.e(LOG_TAG, "Error calling startService for exception reporting service: " + Log.getStackTraceString(e)); } }
From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java
private boolean ingress_running_in_foreground() { String ingress_app_name = this.getApplicationContext().getString(R.string.ingress_process_name); ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); // The first in the list of RunningTasks is always the foreground task. int index2ask = 0; if (overlayView.isVisible()) { index2ask = 1;/*from w w w . java2s . c om*/ } ActivityManager.RunningTaskInfo foregroundTaskInfo = am.getRunningTasks(index2ask + 1).get(0); String foregroundTaskPackageName = foregroundTaskInfo.topActivity.getPackageName(); PackageManager pm = this.getPackageManager(); PackageInfo foregroundAppPackageInfo = null; try { foregroundAppPackageInfo = pm.getPackageInfo(foregroundTaskPackageName, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String foregroundTaskAppName = foregroundAppPackageInfo.applicationInfo.loadLabel(pm).toString(); Log.i("julin", foregroundTaskAppName + " " + index2ask + " " + (overlayView.isVisible() ? "SI" : "NO")); return foregroundTaskAppName.equals("Ingress"); }
From source file:com.brq.wallet.activity.export.BackupToPdfActivity.java
private String getFileProviderAuthority() { try {//from ww w . ja v a2s. c o m PackageManager packageManager = getApplication().getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_PROVIDERS); for (ProviderInfo info : packageInfo.providers) { if (info.name.equals("android.support.v4.content.FileProvider")) { return info.authority; } } } catch (NameNotFoundException e) { throw new RuntimeException(e); } throw new RuntimeException("No file provider authority specified in manifest"); }
From source file:com.groupme.sdk.GroupMeConnect.java
/** * Checks with the PackageManager on device to see if the GroupMe app is installed. * * @return True if the GroupMe app is installed or false if it is not. * @since 1/*w w w . j av a 2 s.c o m*/ */ public boolean hasGroupMeAppInstalled() { PackageManager manager = mContext.getPackageManager(); try { PackageInfo info = manager.getPackageInfo(GROUP_ME_APP_PACKAGE, 0); return info.packageName.equals(GROUP_ME_APP_PACKAGE); } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:com.samsung.smcl.example.helloworldprovider.backend.HelloWorldProviderService.java
private boolean isAppInstalled(String uri) { PackageManager pm = getPackageManager(); try {/*from ww w . java2 s . c om*/ pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { Utility.logError(TAG, "", e); return false; } }