List of usage examples for android.content.pm PackageManager GET_META_DATA
int GET_META_DATA
To view the source code for android.content.pm PackageManager GET_META_DATA.
Click Source Link
From source file:com.echopf.ECHOFcmListenerService.java
@Override public void onMessageReceived(RemoteMessage message) { String from = message.getFrom(); Map<String, String> payload = message.getData(); Bundle data = new Bundle(); for (String key : payload.keySet()) { data.putString(key, payload.get(key)); }// w w w.j a v a 2 s . co m if (!data.containsKey("message") && !data.containsKey("title")) return; // get ApplicationInfo ApplicationInfo appInfo = null; try { appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { throw new RuntimeException(e); } // make notification id int id = (appInfo.metaData.getBoolean(NOTIFY_ONLY_LATEST_KEY, false)) ? 0 : (int) System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = getNotificationBuilder(data); notificationManager.notify(id, builder.build()); }
From source file:it.scoppelletti.mobilepower.app.AppUtils.java
/** * Restituisce il nome del pacchetto di un’applicazione. * /*www . j a va 2s. c om*/ * @param ctx Contesto. * @param onlyIfDemo Indica se restituire il nome del pacchetto solo se * l’applicazione è una versione di demo. * @return Nome del pacchetto. Se il parametro {@code onlyIfDemo} * è impostato, può essere {@code null}. */ static String getFullPackageName(Context ctx, boolean onlyIfDemo) { String pkgName, value; Bundle data; ApplicationInfo applInfo; PackageManager pkgMgr; if (ctx == null) { throw new NullPointerException("Argument ctx is null."); } pkgName = ctx.getPackageName(); pkgMgr = ctx.getPackageManager(); try { applInfo = pkgMgr.getApplicationInfo(pkgName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException ex) { myLogger.error("Failed to get ApplicationInfo.", ex); applInfo = ctx.getApplicationInfo(); } data = applInfo.metaData; value = (data != null) ? data.getString(AppUtils.METADATA_FULLPACKAGE) : null; if (!StringUtils.isBlank(value)) { pkgName = value; } else if (onlyIfDemo) { return null; } return pkgName; }
From source file:com.emetophobe.permissionviewer.PermissionScanner.java
@Override public void run() { // Get the list of installed packages PackageManager pm = mContext.getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); // Send a message to the main thread to display the progress dialog sendMessage(MESSAGE_PROGRESS_INIT, packages.size()); String packageName, appName, permissionName; PackageInfo packageInfo;// w w w .j av a 2 s. c o m boolean system; int count = 0; // Iterate over each package in the list for (ApplicationInfo appInfo : packages) { // Get the package name and label packageName = appInfo.packageName; try { appName = pm.getApplicationLabel(appInfo).toString(); } catch (Resources.NotFoundException e) { // application not found appName = packageName; } // Get the system flag system = (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; try { // Get the list of permissions packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); if (packageInfo.requestedPermissions != null) { for (int i = 0; i < packageInfo.requestedPermissions.length; ++i) { if (packageInfo.requestedPermissions[i].startsWith(ANDROID_PERMISSION)) { permissionName = packageInfo.requestedPermissions[i] .substring(ANDROID_PERMISSION.length()); // Add a separate entry for each permission addPackage(appName, packageName, permissionName, system); } } } else { // Add an empty permission entry for packages that contain zero permissions addPackage(appName, packageName, null, system); } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, e.toString()); } // Send a message to the main thread to update the progress dialog sendMessage(MESSAGE_PROGRESS_UPDATE, ++count); } // Send a message to the main thread that the thread is finished. sendMessage(MESSAGE_PROGRESS_COMPLETE, 0); }
From source file:com.pspdfkit.cordova.PSPDFCordovaPlugin.java
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); try {//from w w w . ja v a 2 s . c o m licenseKey = cordova.getActivity().getPackageManager().getApplicationInfo( cordova.getActivity().getPackageName(), PackageManager.GET_META_DATA).metaData .getString(METADATA_LICENSE_KEY, null); } catch (PackageManager.NameNotFoundException e) { throw new PSPDFCordovaPluginException("Error while reading PSPDFKit license from AndroidManifest.xml", e); } if (TextUtils.isEmpty(licenseKey)) { throw new PSPDFCordovaPluginException( "PSPDFKit license key is missing! Please add a <meta-data android:name=\"PSPDFKIT_LICENSE_KEY\" android:value=\"...\"> to your AndroidManifest.xml."); } try { PSPDFKit.initialize(cordova.getActivity(), licenseKey); } catch (Exception ex) { throw new PSPDFCordovaPluginException("Error while initializing PSPDFKit", ex); } }
From source file:org.deviceconnect.android.deviceplugin.kadecot.fragment.KadecotInstallFragment.java
/** * Check install Kadecot package.//from w ww . j a v a2 s . c o m * * @return true : installed, false : Not install. */ private boolean isInstalledKadecotPackage() { String appId = getString(R.string.kadecot_package_name); try { PackageManager pm = getActivity().getPackageManager(); ApplicationInfo appInfo = pm.getApplicationInfo(appId, PackageManager.GET_META_DATA); if (appInfo != null) { return true; } } catch (PackageManager.NameNotFoundException e) { return false; } return false; }
From source file:com.microsoft.azure.engagement.unity.EngagementWrapper.java
public static void registerApp(String _instanceName, String _connectionString, int _locationType, int _locationMode, boolean _enablePluginLog) { unityObjectName = _instanceName;// ww w.ja v a 2 s. c o m if (androidActivity == null) { Log.e(EngagementShared.LOG_TAG, "missing AndroidActivty (setAndroidActivity() not being called?)"); return; } if (EngagementShared.instance().alreadyInitialized()) { Log.e(EngagementShared.LOG_TAG, "registerApp() already called"); return; } try { ApplicationInfo ai = androidActivity.getPackageManager() .getApplicationInfo(androidActivity.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; String mfPluginVersion = bundle.getString("engagement:unity:version"); if (mfPluginVersion == null) throw new PackageManager.NameNotFoundException(); if (pluginVersion.equals(mfPluginVersion) == false) Log.i(EngagementShared.LOG_TAG, "Unity Plugin Version (" + pluginVersion + ") does not match manifest version (" + mfPluginVersion + ") : Manifest might need to be regenerated"); } catch (Exception e) { Log.e(EngagementShared.LOG_TAG, "Cannot find engagement:unity:version in Android Manifest : Manifest file needs to be generated through File/Engagement/Generate Android Manifest"); } EngagementShared.instance().setPluginLog(_enablePluginLog); EngagementShared.instance().initSDK(pluginName, pluginVersion, nativeVersion); EngagementShared.instance().setDelegate(engagementDelegate); EngagementShared.locationReportingType locationReporting = EngagementShared.locationReportingType .fromInteger(_locationType); EngagementShared.backgroundReportingType background = EngagementShared.backgroundReportingType .fromInteger(_locationMode); EngagementShared.instance().initialize(androidActivity, _connectionString, locationReporting, background); // We consider the app to be active on registerApp as onResume() is not being automatically called EngagementShared.instance().onResume(); }
From source file:org.deviceconnect.android.deviceplugin.linking.setting.fragment.LinkingImageFragment.java
private boolean isApplicationInstalled(final Context context) { try {//from w w w. j av a 2s . co m context.getPackageManager().getPackageInfo(PACKAGE_NAME, PackageManager.GET_META_DATA); return true; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return false; }
From source file:de.madvertise.android.sdk.MadUtil.java
/** * Returns the madvertise token//from w w w.ja v a 2 s . com * * @param context * application context * @return madvertise_token from AndroidManifest.xml or null */ protected static String getToken(Context context) { String madvertiseToken = null; PackageManager packageManager = context.getPackageManager(); try { ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); madvertiseToken = applicationInfo.metaData.getString("madvertise_site_token"); } catch (Exception e) { e.printStackTrace(); } if (madvertiseToken == null) { if (PRINT_LOG) Log.d(MadUtil.LOG, "Could not fetch \"madvertise_site_token\" from AndroidManifest.xml"); } return madvertiseToken; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * ?AndroidManifestmeta-data// ww w . j a va 2 s . co m * * @return ??() */ public static int getIntMeta(final Context context, final String metaName, final int defaultValue) { int meta = defaultValue; try { ApplicationInfo appinfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); if (appinfo != null) { meta = appinfo.metaData.getInt(metaName, defaultValue); } } catch (Exception e) { LogUtil.e(TAG, "", e); } return meta; }
From source file:com.clanofthecloud.cloudbuilder.pushnotifications.RegistrationIntentService.java
@Override protected void onHandleIntent(Intent intent) { try {/* www . j a v a 2 s .com*/ // In the (unlikely) event that multiple refresh operations occur simultaneously, // ensure that they are processed sequentially. synchronized (TAG) { // [START register_for_gcm] // Initially this call goes out to the network to retrieve the token, subsequent calls // are local. // [START get_token] InstanceID instanceID = InstanceID.getInstance(this); ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); Object senderId = ai.metaData.get("cotc.GcmSenderId"); if (senderId == null) { Log.e(TAG, "!!!!!!!!! cotc.GcmSenderId not configured in manifest, push notifications won't work !!!!!!!!!"); senderId = ""; } if (CloudBuilder.sVerboseLog) Log.v(TAG, "Using senderId: " + senderId.toString()); String token = instanceID.getToken(senderId.toString(), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); // [END get_token] if (CloudBuilder.sVerboseLog) Log.v(TAG, "GCM Registration Token: " + token); registrationToken = token; // Subscribe to topic channels if (intent.getBooleanExtra(UNREGISTER_PARAM, false)) { unsubscribeTopics(token); } else { subscribeTopics(token); } // [END register_for_gcm] // Call handler if (handlerCalledWhenRegistrationTokenReceived != null) { JSONObject obj = new JSONObject(); obj.put("token", token); handlerCalledWhenRegistrationTokenReceived.onDone(EErrorCode.enNoErr, obj, null); } } } catch (Exception e) { Log.w(TAG, "Failed to complete token refresh", e); // If an exception happens while fetching the new token or updating our registration data // on a third-party server, this ensures that we'll attempt the update at a later time. // sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply(); } // Notify UI that registration has completed, so the progress indicator can be hidden. Intent registrationComplete = new Intent(Controller.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); }