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.microsoft.azure.engagement.cordova.AZME.java
public void initialize(CordovaInterface _cordova, CordovaWebView _webView) { CordovaActivity activity = (CordovaActivity) _cordova.getActivity(); String invokeString = activity.getIntent().getDataString(); super.initialize(_cordova, _webView); cordova = _cordova;/*from w ww. j a v a 2 s . c om*/ webView = _webView; try { ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; boolean nativeLog = bundle.getBoolean("engagement:log:test"); boolean pluginLog = bundle.getBoolean("AZME_ENABLE_PLUGIN_LOG"); EngagementShared.instance().setPluginLog(pluginLog); EngagementShared.instance().initSDK(pluginName, pluginVersion, nativeSDKVersion); if (invokeString != null && !invokeString.equals("")) { lastRedirect = invokeString; EngagementShared.instance().logD("handleOpenURL=" + lastRedirect); } lazyAreaLocation = bundle.getBoolean("AZME_LAZYAREA_LOCATION"); realtimeLocation = bundle.getBoolean("AZME_REALTIME_LOCATION"); fineRealtimeLocation = bundle.getBoolean("AZME_FINEREALTIME_LOCATION"); backgroundReporting = bundle.getBoolean("AZME_BACKGROUND_REPORTING"); foregroundReporting = bundle.getBoolean("AZME_FOREGROUND_REPORTING"); String connectionString = bundle.getString("AZME_ANDROID_CONNECTION_STRING"); EngagementShared.backgroundReportingType background = EngagementShared.backgroundReportingType.BACKGROUNDREPORTING_NONE; EngagementShared.locationReportingType locationReporting = EngagementShared.locationReportingType.LOCATIONREPORTING_NONE; if (lazyAreaLocation) locationReporting = EngagementShared.locationReportingType.LOCATIONREPORTING_LAZY; else if (realtimeLocation) locationReporting = EngagementShared.locationReportingType.LOCATIONREPORTING_REALTIME; else if (fineRealtimeLocation) locationReporting = EngagementShared.locationReportingType.LOCATIONREPORTING_FINEREALTIME; if (backgroundReporting) background = EngagementShared.backgroundReportingType.BACKGROUNDREPORTING_BACKGROUND; else if (foregroundReporting) background = EngagementShared.backgroundReportingType.BACKGROUNDREPORTING_FOREGROUND; EngagementShared.instance().initialize(activity, connectionString, locationReporting, background); EngagementShared.instance().setDelegate(delegate); } catch (PackageManager.NameNotFoundException e) { EngagementShared.instance().logE("Failed to load meta-data, NameNotFound: " + e.getMessage()); } catch (NullPointerException e) { EngagementShared.instance().logE("Failed to load meta-data, NullPointer: " + e.getMessage()); } }
From source file:com.clanofthecloud.cotcpushnotifications.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* www . j a v a 2s . c o m*/ */ private void sendNotification(String message) { Activity currentAct = UnityPlayer.currentActivity; Class activityToOpen = currentAct != null ? currentAct.getClass() : UnityPlayerActivity.class; Intent intent = new Intent(this, activityToOpen); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); ApplicationInfo ai = null; try { ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); int notificationIcon = ai.metaData.getInt("cotc.GcmNotificationIcon", -1); if (notificationIcon == -1) { Log.e(TAG, "!!!!!!!!! cotc.GcmNotificationIcon not configured in manifest, push notifications won't work !!!!!!!!!"); return; } int notificationLargeIcon = ai.metaData.getInt("cotc.GcmNotificationLargeIcon", -1); if (notificationLargeIcon == -1) { Log.e(TAG, "There is no large icon for push notifs, will only use default icon"); return; } String pushNotifName = ai.metaData.getString("cotc.GcmNotificationTitle"); if (pushNotifName == null) { Log.e(TAG, "!!!!!!!!! cotc.GcmNotificationTitle not configured in manifest, push notifications won't work !!!!!!!!!"); return; } if (notifManager == null) notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notificationBuilder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { int importance = NotificationManager.IMPORTANCE_HIGH; NotificationChannel channel = new NotificationChannel("CotC Channel", "CotC Channel", importance); channel.setDescription("CotC Channel"); notifManager.createNotificationChannel(channel); notificationBuilder = new NotificationCompat.Builder(this, "CotC Channel"); } else notificationBuilder = new NotificationCompat.Builder(this); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); notificationBuilder.setSmallIcon(notificationIcon).setContentTitle(pushNotifName) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent).setPriority(Notification.PRIORITY_HIGH); if (notificationLargeIcon != -1) notificationBuilder.setLargeIcon( BitmapFactory.decodeResource(currentAct.getResources(), notificationLargeIcon)); notifManager.notify(0 /* ID of notification */, notificationBuilder.build()); } catch (Exception e) { Log.w(TAG, "Failed to handle push notification", e); } }
From source file:org.openmrs.mobile.activities.settings.SettingsFragment.java
@Override public void addBuildVersionInfo() { String versionName = ""; int buildVersion = 0; PackageManager packageManager = this.getActivity().getPackageManager(); String packageName = this.getActivity().getPackageName(); try {/*www . j a va 2 s . c o m*/ versionName = packageManager.getPackageInfo(packageName, 0).versionName; ApplicationInfo ai = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA); buildVersion = ai.metaData.getInt("buildVersion"); } catch (PackageManager.NameNotFoundException e) { mPresenter.logException("Failed to load meta-data, NameNotFound: " + e.getMessage()); } catch (NullPointerException e) { mPresenter.logException("Failed to load meta-data, NullPointer: " + e.getMessage()); } mListItem.add(new SettingsListItemDTO(getResources().getString(R.string.settings_about), getResources().getString(R.string.app_name), versionName + " Build: " + buildVersion)); }
From source file:it.scoppelletti.mobilepower.app.AboutActivity.java
/** * Costruisce il testo da visualizzare.//w w w . ja v a 2s .co m * * @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.projecto.mapav2.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try {/* ww w .j ava 2 s. c o m*/ setContentView(R.layout.activity_main); mapa = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (mapa != null) { mapa.addMarker(new MarkerOptions().position(LOCATION_SURRREY).title("Find me here!")); mapa.setMyLocationEnabled(true); mapa.setTrafficEnabled(true); mapa.setMapType(GoogleMap.MAP_TYPE_HYBRID); } gps = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); GlEsVersion = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)) .getDeviceConfigurationInfo().getGlEsVersion(); try { versionCode = context.getPackageManager().getPackageInfo("com.android.vending", 0).versionCode; versionCode2 = context.getPackageManager().getPackageInfo("com.google.android.gms", 0).versionCode; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { pm = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData.getString("com.google.android.maps.v2.API_KEY"); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000; Toast.makeText(MainActivity.this, "isGooglePlayServicesAvailable" + gps + "\n" + "GlEsVersion " + GlEsVersion + "\n" + "versionCode Vending" + versionCode + "\nversionCode GMS " + versionCode2 + "\n" + "getPackageManager " + pm + "\n" + "supportsEs2 " + supportsEs2 + "\n" + "getVersionFromPackageManager " + getVersionFromPackageManager(this) + "\n", Toast.LENGTH_LONG).show(); } catch (Exception e) { e.printStackTrace(); Log.d(INPUT_SERVICE, e.toString()); } int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); Log.e("Maps", "Result int value::" + result); switch (result) { case ConnectionResult.SUCCESS: Log.e("Maps", "RESULT:: SUCCESS"); break; case ConnectionResult.DEVELOPER_ERROR: Log.e("Maps", "RESULT:: DE"); break; case ConnectionResult.INTERNAL_ERROR: Log.e("Maps", "RESULT:: IE"); break; case ConnectionResult.INVALID_ACCOUNT: Log.e("Maps", "RESULT:: IA"); break; case ConnectionResult.NETWORK_ERROR: Log.e("Maps", "RESULT:: NE"); break; case ConnectionResult.RESOLUTION_REQUIRED: Log.e("Maps", "RESULT:: RR"); break; case ConnectionResult.SERVICE_DISABLED: Log.e("Maps", "RESULT:: SD"); break; case ConnectionResult.SERVICE_INVALID: Log.e("Maps", "RESULT:: SI"); break; case ConnectionResult.SERVICE_MISSING: Log.e("Maps", "RESULT:: SM"); break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: Log.e("Maps", "RESULT:: SVUR"); break; case ConnectionResult.SIGN_IN_REQUIRED: Log.e("Maps", "RESULT:: SIR"); break; default: break; } mapa.setMapType(GoogleMap.MAP_TYPE_NORMAL); mapa.setMyLocationEnabled(true); Log.e("Maps", "------EOC-------"); }
From source file:at.diamonddogs.net.WebClient.java
/** * Constructs a {@link WebClient}//from ww w.j av a 2 s .co m * * @param context a context */ public WebClient(Context context) { try { ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); followProtocolRedirect = ai.metaData.getBoolean(context.getPackageName() + ".followProtocolRedirect"); } catch (Throwable th) { followProtocolRedirect = false; } }
From source file:com.cw.litenote.config.About.java
void aboutDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); PackageInfo pInfo = null;/*from w w w . j ava 2 s . co m*/ String version_name = "NA"; int version_code = 0; try { Context context = getActivity(); pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { e.printStackTrace(); } if (pInfo != null) { version_name = pInfo.versionName; version_code = pInfo.versionCode; } String msgStr = getActivity().getResources().getString(R.string.about_version_name) + " : " + version_name + "\n" + getActivity().getResources().getString(R.string.about_version_code) + " : " + version_code + "\n\n" + getActivity().getResources().getString(R.string.EULA_string); builder.setTitle(R.string.about_version).setMessage(msgStr).setNegativeButton(R.string.notices_close, null) .show(); }
From source file:fr.inria.ucn.collectors.RunningAppsCollector.java
@SuppressLint("NewApi") @Override/*ww w .ja va 2s . co m*/ public void run(Context c, long ts) { try { ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE); PackageManager pm = c.getPackageManager(); JSONObject data = new JSONObject(); // running tasks JSONArray runTaskArray = new JSONArray(); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(50); boolean first = true; for (ActivityManager.RunningTaskInfo info : taskInfo) { JSONObject jinfo = new JSONObject(); jinfo.put("task_id", info.id); jinfo.put("task_num_activities", info.numActivities); jinfo.put("task_num_running", info.numRunning); // is this the foreground process ? jinfo.put("task_foreground", first); if (first) { first = false; } if (info.topActivity != null) { jinfo.put("task_top_class_name", info.topActivity.getClassName()); jinfo.put("task_top_package_name", info.topActivity.getPackageName()); try { // map package name to app label CharSequence appLabel = pm.getApplicationLabel(pm.getApplicationInfo( info.topActivity.getPackageName(), PackageManager.GET_META_DATA)); jinfo.put("task_app_label", appLabel.toString()); } catch (NameNotFoundException e) { } } runTaskArray.put(jinfo); } data.put("runningTasks", runTaskArray); // processes JSONArray runProcArray = new JSONArray(); for (ActivityManager.RunningAppProcessInfo pinfo : am.getRunningAppProcesses()) { JSONObject jinfo = new JSONObject(); jinfo.put("proc_uid", pinfo.uid); jinfo.put("proc_name", pinfo.processName); jinfo.put("proc_packages", Helpers.getPackagesForUid(c, pinfo.uid)); runProcArray.put(jinfo); } data.put("runningAppProcesses", runProcArray); // done Helpers.sendResultObj(c, "running_apps", ts, data); } catch (JSONException jex) { Log.w(Constants.LOGTAG, "failed to create json obj", jex); } }
From source file:com.github.javiersantos.piracychecker.LibraryUtils.java
@SuppressLint("SdCardPath") static PirateApp getPirateApp(Context context, boolean lpf, boolean stores) { if (!lpf && !stores) return null; for (PirateApp app : getApps()) { if ((lpf && app.isUnauthorized()) || (stores && !app.isUnauthorized())) { StringBuilder builder = new StringBuilder(); for (String s : app.getPack()) { builder.append(s);//from w ww . j av a2 s . c om } String pack = builder.toString(); PackageManager pm = context.getPackageManager(); try { PackageInfo info = pm.getPackageInfo(pack, PackageManager.GET_META_DATA); if (info != null) return app; } catch (PackageManager.NameNotFoundException ignored1) { try { Intent intent = pm.getLaunchIntentForPackage(pack); if (isIntentAvailable(context, intent)) { return app; } } catch (Exception ignored2) { try { if (hasPermissions(context)) { File file1 = new File("/data/app/" + pack + "-1/base.apk"); File file2 = new File("/data/app/" + pack + "-2/base.apk"); File file3 = new File("/data/app/" + pack + ".apk"); File file4 = new File("/data/data/" + pack + ".apk"); File file5 = new File("/data/data/" + pack); File file6 = new File(context.getFilesDir().getPath() + pack + ".apk"); File file7 = new File(context.getFilesDir().getPath() + pack); File file8 = new File( Environment.getExternalStorageDirectory() + "/Android/data/" + pack); if (file1.exists() || file2.exists() || file3.exists() || file4.exists() || file5.exists() || file6.exists() || file7.exists() || file8.exists()) { return app; } } } catch (Exception ignored) { } } } } } return null; }
From source file:com.scm.reader.livescanner.search.ImageRecognizer.java
public Search query(final Context context, Search dataToPopulate) throws IOException { String searchUrl = KConfig.getConfig().getServer(); LogUtils.logDebug("qurl " + searchUrl); String apiKey = null;//w w w . j a va2 s. c o m String apiSecret = null; try { ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; apiKey = bundle.getString(API_KEY_NAME); apiSecret = bundle.getString(API_SECRET_NAME); } catch (NameNotFoundException e) { Log.e(TAG, "Failed to load API_KEY or SECRET from meta-data, NameNotFound: " + e.getMessage()); throw new RuntimeException("API_KEY or SECRET not found."); } catch (NullPointerException e) { Log.e(TAG, "Failed to load API_KEY or SECRET from meta-data, NullPointer: " + e.getMessage()); throw new RuntimeException("API_KEY or SECRET not found."); } SearchRequestBuilder requestBuilderV4 = new SearchRequestBuilder( new SearchRequestData(dataToPopulate.getImage(), dataToPopulate.getLatitude(), dataToPopulate.getLongitude(), searchUrl, getDeviceId(context)), getPackageInfo(context), apiKey, apiSecret); String response = ""; try { Map<String, String> params = new HashMap<String, String>(); params.put("location:", dataToPopulate.getLatitude() + ", " + dataToPopulate.getLongitude()); response = requestBuilderV4.query(); } catch (InvalidKeyException e1) { e1.printStackTrace(); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (IOException e) { LogUtils.logWarn("IO exception while sending HTTP request and parsing response", e); throw e; } // Print the response to console System.out.println("HTTP Status: " + requestBuilderV4.getResponseStatus()); System.out.println("HTTP Response: " + requestBuilderV4.getResponseBody()); Search result = null; try { result = parseJSON(context, response, dataToPopulate); } catch (JSONException e) { e.printStackTrace(); } return result; }