Example usage for android.content.pm PackageManager GET_META_DATA

List of usage examples for android.content.pm PackageManager GET_META_DATA

Introduction

In this page you can find the example usage for android.content.pm PackageManager GET_META_DATA.

Prototype

int GET_META_DATA

To view the source code for android.content.pm PackageManager GET_META_DATA.

Click Source Link

Document

ComponentInfo flag: return the ComponentInfo#metaData data android.os.Bundle s that are associated with a component.

Usage

From source file:com.franmontiel.fcmnotificationhandler.RemoteMessageToNotificationMapper.java

private int getResourceIdFromApplicationMetadata(String metadataName) {
    int resourceId = 0;
    try {//from   ww  w . java 2 s  .  c o  m
        Bundle appMetadata = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA).metaData;
        resourceId = appMetadata.getInt(metadataName, 0);

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return resourceId;
}

From source file:com.onesignal.NotificationExtenderService.java

static Intent getIntent(Context context) {
    PackageManager packageManager = context.getPackageManager();
    Intent intent = new Intent().setAction("com.onesignal.NotificationExtender")
            .setPackage(context.getPackageName());
    List<ResolveInfo> resolveInfo = packageManager.queryIntentServices(intent, PackageManager.GET_META_DATA);
    if (resolveInfo.size() < 1)
        return null;

    return intent;
}

From source file:it.unicaradio.android.activities.MainActivity.java

private boolean hasBeenUpdated() {
    try {/*from w w  w. jav  a2 s .c o m*/
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
        long lastRunVersionCode = preferences.getLong(UnicaradioPreferences.PREF_LASTRUNVERSIONCODE, 0);
        if (lastRunVersionCode < pInfo.versionCode) {
            Editor editor = preferences.edit();
            editor.putLong("lastRunVersionCode", pInfo.versionCode);
            editor.commit();

            return (lastRunVersionCode > 0);
        }
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Error while verifying if app has been updated", e);
    }

    return false;
}

From source file:io.nuclei.cyto.share.ShareIntent.java

/**
 * Create a default share intent for the purposes of requesting activities that can
 * handle this intent.//from www. j  a va  2  s .co  m
 */
public Intent createDefaultShareIntent(Context context) {
    String authority;
    try {
        ApplicationInfo applicationInfo = context.getApplicationContext().getPackageManager()
                .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
        authority = applicationInfo.metaData.getString(SHARING_AUTHORITY);
    } catch (Exception err) {
        throw new RuntimeException(err);
    }
    if (TextUtils.isEmpty(authority))
        Log.w(TAG, MISSING_CONFIG);
    PackageTargetManager manager = mDefaultTargetManager == null ? new DefaultPackageTargetManager()
            : mDefaultTargetManager;
    manager.initialize(mText, mUri, mUrl, mEmail, mSubject, mFile);
    return manager.onCreateIntent(context, authority);
}

From source file:nuclei.ui.share.ShareIntent.java

/**
 * Create a default share intent for the purposes of requesting activities that can
 * handle this intent.//from  w w  w  . j a v  a2 s. c om
 */
public Intent createDefaultShareIntent(Context context) {
    String authority;
    try {
        ApplicationInfo applicationInfo = context.getApplicationContext().getPackageManager()
                .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
        authority = applicationInfo.metaData.getString(SHARING_AUTHORITY);
    } catch (Exception err) {
        throw new RuntimeException(err);
    }
    if (TextUtils.isEmpty(authority))
        Log.w(TAG, MISSING_CONFIG);
    PackageTargetManager manager = mDefaultTargetManager == null ? new DefaultPackageTargetManager()
            : mDefaultTargetManager;
    manager.initialize(mText, mUri, mUrl, mSms, mEmail, mSubject, mFile);
    return manager.onCreateIntent(context, authority);
}

From source file:de.mrapp.android.preference.activity.PreferenceFragment.java

/**
 * Obtains the resource id of the activity's current theme.
 *
 * @return The resource id of the acitivty's current theme as an {@link Integer} value or 0, if
 * an error occurred while obtaining the theme
 *//*from   w  ww  . j a v  a  2 s.c o m*/
private int obtainTheme() {
    try {
        String packageName = getActivity().getClass().getPackage().getName();
        PackageInfo packageInfo = getActivity().getPackageManager().getPackageInfo(packageName,
                PackageManager.GET_META_DATA);
        return packageInfo.applicationInfo.theme;
    } catch (NameNotFoundException e) {
        return 0;
    }
}

From source file:com.NotifyMe.GcmIntentService.java

private Intent getWeatherAppIntent() {
    final PackageManager pm = getPackageManager();
    //get a list of installed apps.
    String genieWidgetPackage = null;
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    for (ApplicationInfo packageInfo : packages) {
        if (packageInfo.packageName.toLowerCase().contains("weather")) {
            return pm.getLaunchIntentForPackage(packageInfo.packageName);
        } else if (packageInfo.packageName.toLowerCase().contains("geniewidget")) {
            genieWidgetPackage = packageInfo.packageName;
        }/*ww w . ja va2  s.  c om*/
    }
    // Didn't find a weather app - Try Google News and Weather
    // Will return null if not found.
    return pm.getLaunchIntentForPackage(genieWidgetPackage);
}

From source file:com.ameron32.apps.tapnotes._unused.original.LoginActivity.java

private Bundle getMergedOptions() {
    // Read activity metadata from AndroidManifest.xml
    ActivityInfo activityInfo = null;/*from   w  w w  . jav  a  2s .c o  m*/
    try {
        activityInfo = getPackageManager().getActivityInfo(this.getComponentName(),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        if (Parse.getLogLevel() <= Parse.LOG_LEVEL_ERROR && Log.isLoggable(LOG_TAG, Log.WARN)) {
            Log.w(LOG_TAG, e.getMessage());
        }
    }

    // The options specified in the Intent (from ParseLoginBuilder) will
    // override any duplicate options specified in the activity metadata
    Bundle mergedOptions = new Bundle();
    if (activityInfo != null && activityInfo.metaData != null) {
        mergedOptions.putAll(activityInfo.metaData);
    }
    if (getIntent().getExtras() != null) {
        mergedOptions.putAll(getIntent().getExtras());
    }

    return mergedOptions;
}

From source file:com.rp.podemu.SettingsActivity.java

private void setCtrlApplicationInfo() {
    String processName = sharedPref.getString("ControlledAppProcessName", "unknown application");

    PackageManager pm = getPackageManager();
    ApplicationInfo appInfo;//from   ww w  .  j av a 2s.  c o  m
    TextView textView = (TextView) findViewById(R.id.ctrlAppName);

    try {
        appInfo = pm.getApplicationInfo(processName, PackageManager.GET_META_DATA);

        textView.setText(appInfo.loadLabel(pm));

        ImageView imageView = (ImageView) findViewById(R.id.ctrlAppIcon);
        imageView.setImageDrawable(appInfo.loadIcon(pm));

    } catch (PackageManager.NameNotFoundException e) {
        textView.setText("Cannot load application ");
    }

}

From source file:com.parse.starter.ParseLoginActivity.java

/**
 * @see android.app.Activity#isDestroyed()
 *///from   www  .  j ava  2 s.c  o m
//  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
//  @Override
//  public boolean isDestroyed() {
//    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
//      return super.isDestroyed();
//    }
//    return destroyed;
//  }

private Bundle getMergedOptions() {
    // Read activity metadata from AndroidManifest.xml
    ActivityInfo activityInfo = null;
    try {
        activityInfo = getPackageManager().getActivityInfo(this.getComponentName(),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        if (Parse.getLogLevel() <= Parse.LOG_LEVEL_ERROR && Log.isLoggable(LOG_TAG, Log.WARN)) {
            Log.w(LOG_TAG, e.getMessage());
        }
    }

    // The options specified in the Intent (from ParseLoginBuilder) will
    // override any duplicate options specified in the activity metadata
    Bundle mergedOptions = new Bundle();
    if (activityInfo != null && activityInfo.metaData != null) {
        mergedOptions.putAll(activityInfo.metaData);
    }
    if (getIntent().getExtras() != null) {
        mergedOptions.putAll(getIntent().getExtras());
    }

    return mergedOptions;
}