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:crow.util.Util.java

/**
 * ? meta   <code>// w w w .  j av a 2  s .c  o m
 * <meta-data android:name="keyName"
 * android:value="0123456789abc" />
 * </code>
 * 
 * @param context
 * @param keyName
 *            name of meta-data
 * @return value of meta-data null ?
 */
public static String readMetaByKey(Context context, String keyName) {
    try {
        ApplicationInfo appi = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = appi.metaData;
        return (String) bundle.get(keyName);
    } catch (Exception e) {
        return null;
    }
}

From source file:org.opensilk.music.ui3.main.LibraryProviderInfoLoader.java

public Observable<LibraryProviderInfo> makeObservable() {
    return Observable.create(new Observable.OnSubscribe<List<ProviderInfo>>() {
        @Override/*from w  ww  . ja  v a 2 s  .co  m*/
        public void call(Subscriber<? super List<ProviderInfo>> subscriber) {
            final PackageManager pm = context.getPackageManager();
            final List<ProviderInfo> providerInfos = pm.queryContentProviders(null, 0,
                    PackageManager.GET_META_DATA);
            subscriber.onNext(providerInfos);
            subscriber.onCompleted();
        }
    }).flatMap(new Func1<List<ProviderInfo>, Observable<ProviderInfo>>() {
        @Override
        public Observable<ProviderInfo> call(List<ProviderInfo> providerInfos) {
            return Observable.from(providerInfos);
        }
    }).filter(new Func1<ProviderInfo, Boolean>() {
        @Override
        public Boolean call(ProviderInfo providerInfo) {
            return StringUtils.startsWith(providerInfo.authority, LibraryProvider.AUTHORITY_PFX)
                    //Ignore non exported providers unless they're ours
                    && (StringUtils.equals(providerInfo.packageName, context.getPackageName())
                            || providerInfo.exported);
        }
    }).map(new Func1<ProviderInfo, LibraryProviderInfo>() {
        @Override
        public LibraryProviderInfo call(ProviderInfo providerInfo) {
            final PackageManager pm = context.getPackageManager();
            final String authority = providerInfo.authority;
            final CharSequence title = providerInfo.loadLabel(pm);
            final ComponentName cn = new ComponentName(providerInfo.packageName, providerInfo.name);
            final Drawable icon = providerInfo.loadIcon(pm);
            CharSequence description;
            try {
                Context packageContext = context.createPackageContext(cn.getPackageName(), 0);
                Resources packageRes = packageContext.getResources();
                description = packageRes.getString(providerInfo.descriptionRes);
            } catch (PackageManager.NameNotFoundException e) {
                description = "";
            }
            final LibraryProviderInfo lpi = new LibraryProviderInfo(title.toString(), description.toString(),
                    authority);
            lpi.icon = icon;
            for (String a : settings.readDisabledPlugins()) {
                if (a.equals(lpi.authority)) {
                    lpi.isActive = false;
                    break;
                }
            }
            return lpi;
        }
    });
}

From source file:com.robopupu.component.AppManagerImpl.java

@Override
public boolean isPackageInstalled(final String packageName) {
    final Context context = application.getApplicationContext();
    final PackageManager manager = context.getPackageManager();
    final List<ApplicationInfo> infos = manager.getInstalledApplications(PackageManager.GET_META_DATA);

    for (final ApplicationInfo info : infos) {
        if (packageName.equalsIgnoreCase(info.packageName)) {
            return true;
        }/*from   ww  w .j ava  2 s  . c o  m*/
    }
    return false;
}

From source file:com.samsung.multiwindow.MultiWindow.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {

    if (Log.isLoggable(MULTIWINDOW, Log.DEBUG)) {
        Log.d(TAG, "Initialize multiwindow");
    }//from   w  ww .ja v a 2 s.  c  om
    super.initialize(cordova, webView);
    String packageName = cordova.getActivity().getPackageName();
    PackageManager pm = cordova.getActivity().getPackageManager();
    ApplicationInfo ai = null;
    try {
        ai = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if (ai.metaData != null) {
            pluginMetadata = ai.metaData.getBoolean(META_DATA);
        }
    } catch (NameNotFoundException e) {
        Log.e("MultiWindow", e.getMessage());
    }
}

From source file:com.launcher.silverfish.launcher.appdrawer.AppDrawerTabFragment.java

private boolean addAppToList(String packageName) {
    try {/*  w  w w . ja va  2 s.  c  o m*/
        // Get the information about the app
        ApplicationInfo appInfo = mPacMan.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        AppDetail appDetail = new AppDetail();

        // And add it to the list.
        appDetail.label = mPacMan.getApplicationLabel(appInfo);
        appDetail.icon = null; // Loaded later by AppArrayAdapter
        appDetail.packageName = packageName;
        appsList.add(appDetail);

        hideEmptyCategoryNotice();
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:org.odk.collect.android.activities.SplashScreenActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                MY_PERMISSIONS_WRITE_STORAGE);
    } else {/*from   www.j  a  v a 2 s  .c  om*/
        // must be at the beginning of any activity that can be called from an external intent
        try {
            Collect.createODKDirs();
        } catch (RuntimeException e) {
            createErrorDialog(e.getMessage(), EXIT);
            return;
        }
    }

    mImageMaxWidth = getWindowManager().getDefaultDisplay().getWidth();

    // this splash screen should be a blank slate
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splash_screen);

    // get the shared preferences object
    SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    Editor editor = mSharedPreferences.edit();

    // get the package info object with version number
    PackageInfo packageInfo = null;
    try {
        packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }

    boolean firstRun = mSharedPreferences.getBoolean(PreferencesActivity.KEY_FIRST_RUN, true);
    boolean showSplash = mSharedPreferences.getBoolean(PreferencesActivity.KEY_SHOW_SPLASH, false);
    String splashPath = mSharedPreferences.getString(PreferencesActivity.KEY_SPLASH_PATH,
            getString(R.string.default_splash_path));

    // if you've increased version code, then update the version number and set firstRun to true
    if (mSharedPreferences.getLong(PreferencesActivity.KEY_LAST_VERSION, 0) < packageInfo.versionCode) {
        editor.putLong(PreferencesActivity.KEY_LAST_VERSION, packageInfo.versionCode);
        editor.commit();

        firstRun = true;
    }

    // do all the first run things
    if (firstRun || showSplash) {
        editor.putBoolean(PreferencesActivity.KEY_FIRST_RUN, false);
        editor.commit();
        startSplashScreen(splashPath);
    } else {
        endSplashScreen();
    }

}

From source file:com.adwhirl.AdWhirlLayout.java

protected String getAdWhirlKey(Context context) {
    final String packageName = context.getPackageName();
    final String activityName = context.getClass().getName();
    final PackageManager pm = context.getPackageManager();
    Bundle bundle = null;/*www  .  j a  va2s . c o  m*/
    // Attempts to retrieve Activity-specific AdWhirl key first. If not
    // found, retrieve Application-wide AdWhirl key.
    try {
        ActivityInfo activityInfo = pm.getActivityInfo(new ComponentName(packageName, activityName),
                PackageManager.GET_META_DATA);
        bundle = activityInfo.metaData;
        if (bundle != null) {
            return bundle.getString(AdWhirlLayout.ADWHIRL_KEY);
        }
    } catch (NameNotFoundException exception) {
        // Activity cannot be found. Shouldn't be here.
        return null;
    }

    try {
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        bundle = appInfo.metaData;
        if (bundle != null) {
            return bundle.getString(AdWhirlLayout.ADWHIRL_KEY);
        }
    } catch (NameNotFoundException exception) {
        // Application cannot be found. Shouldn't be here.
        return null;
    }
    return null;
}

From source file:com.battlelancer.seriesguide.util.Utils.java

public static String getVersion(Context context) {
    String version;// w w  w .j  av a  2  s. c  o  m
    try {
        version = context.getPackageManager().getPackageInfo(context.getPackageName(),
                PackageManager.GET_META_DATA).versionName;
    } catch (NameNotFoundException e) {
        version = "UnknownVersion";
    }
    return version;
}

From source file:com.launcher.silverfish.AppDrawerTabFragment.java

private boolean addAppToList(String app_name) {
    try {//from  ww w .j  a  va2s  .  c  o  m
        // Get the information about the app
        ApplicationInfo appInfo = mPacMan.getApplicationInfo(app_name, PackageManager.GET_META_DATA);
        AppDetail appDetail = new AppDetail();

        // And add it to the list.
        appDetail.label = mPacMan.getApplicationLabel(appInfo);
        appDetail.icon = mPacMan.getApplicationIcon(appInfo);
        appDetail.name = app_name;
        appsList.add(appDetail);

        hideEmptyCategoryNotice();
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:com.kaliturin.blacklist.utils.Permissions.java

/**
 * Returns information string about permission
 **/// w  w  w  . j a  va2s . c  om
@Nullable
private static String getPermissionInfo(@NonNull Context context, @NonNull String permission) {
    context = context.getApplicationContext();
    PackageManager pm = context.getPackageManager();
    PermissionInfo info = null;
    try {
        info = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException ex) {
        Log.w(TAG, ex);
    }

    if (info != null) {
        CharSequence label = info.loadLabel(pm);
        if (label == null) {
            label = info.nonLocalizedLabel;
        }
        return label.toString();
    }

    return null;
}