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.google.android.apps.dashclock.ExtensionManager.java

/**
 * Returns a listing of all available (installed) extensions, including those that aren't
 * world-readable.//from ww  w. j a v  a  2  s  . co m
 */
public List<ExtensionListing> getAvailableExtensions() {
    List<ExtensionListing> availableExtensions = new ArrayList<>();
    PackageManager pm = mApplicationContext.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(new Intent(DashClockExtension.ACTION_EXTENSION),
            PackageManager.GET_META_DATA);
    for (ResolveInfo resolveInfo : resolveInfos) {
        ExtensionListing info = new ExtensionListing();
        info.componentName(
                new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name));
        info.title(resolveInfo.loadLabel(pm).toString());
        Bundle metaData = resolveInfo.serviceInfo.metaData;
        if (metaData != null) {
            info.compatible(ExtensionHost.supportsProtocolVersion(metaData.getInt("protocolVersion")));
            info.worldReadable(metaData.getBoolean("worldReadable", false));
            info.description(metaData.getString("description"));
            String settingsActivity = metaData.getString("settingsActivity");
            if (!TextUtils.isEmpty(settingsActivity)) {
                info.settingsActivity(ComponentName
                        .unflattenFromString(resolveInfo.serviceInfo.packageName + "/" + settingsActivity));
            }
        }

        info.icon(resolveInfo.getIconResource());
        availableExtensions.add(info);
    }

    return availableExtensions;
}

From source file:org.apache.cordova.AndroidWebViewClient.java

/**
 * Notify the host application that an SSL error occurred while loading a resource.
 * The host application must call either handler.cancel() or handler.proceed().
 * Note that the decision may be retained for use in response to future SSL errors.
 * The default behavior is to cancel the load.
 *
 * @param view          The WebView that is initiating the callback.
 * @param handler       An SslErrorHandler object that will handle the user's response.
 * @param error         The SSL error object.
 *//*from   ww  w .ja va  2  s  .c o  m*/
@TargetApi(8)
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

    final String packageName = this.cordova.getActivity().getPackageName();
    final PackageManager pm = this.cordova.getActivity().getPackageManager();

    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            handler.proceed();
            return;
        } else {
            // debug = false
            super.onReceivedSslError(view, handler, error);
        }
    } catch (NameNotFoundException e) {
        // When it doubt, lock it out!
        super.onReceivedSslError(view, handler, error);
    }
}

From source file:com.adjust.sdk.Util.java

public static Bundle getApplicationBundle(Context context, Logger logger) {
    final ApplicationInfo applicationInfo;
    try {/*  www .  j a  v a  2s.  c om*/
        String packageName = context.getPackageName();
        applicationInfo = context.getPackageManager().getApplicationInfo(packageName,
                PackageManager.GET_META_DATA);
        return applicationInfo.metaData;
    } catch (NameNotFoundException e) {
        logger.error("ApplicationInfo not found");
    } catch (Exception e) {
        logger.error("Failed to get ApplicationBundle (%s)", e);
    }
    return null;
}

From source file:plugin.google.maps.CordovaGoogleMaps.java

@SuppressLint("NewApi")
@Override/*from  ww w. j a  v a  2 s.c  o m*/
public void initialize(final CordovaInterface cordova, final CordovaWebView webView) {
    super.initialize(cordova, webView);
    if (root != null) {
        return;
    }
    activity = cordova.getActivity();
    final View view = webView.getView();
    view.getViewTreeObserver().addOnScrollChangedListener(CordovaGoogleMaps.this);
    root = (ViewGroup) view.getParent();

    Method[] classMethods = this.getClass().getMethods();
    for (int i = 0; i < classMethods.length; i++) {
        String methodName = classMethods[i].getName();
        methods.put(methodName, methodName.hashCode());
    }

    pluginManager = webView.getPluginManager();

    cordova.getActivity().runOnUiThread(new Runnable() {
        @SuppressLint("NewApi")
        public void run() {

            // Enable this, webView makes draw cache on the Android action bar issue.
            //View view = webView.getView();
            //if (Build.VERSION.SDK_INT >= 21 || "org.xwalk.core.XWalkView".equals(view.getClass().getName())){
            //  view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            //  Log.d("Layout", "--> view =" + view.isHardwareAccelerated()); //always false
            //}

            // ------------------------------
            // Check of Google Play Services
            // ------------------------------
            int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);

            Log.d(TAG,
                    "----> checkGooglePlayServices = " + (ConnectionResult.SUCCESS == checkGooglePlayServices));

            if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
                // google play services is missing!!!!
                /*
                 * Returns status code indicating whether there was an error. Can be one
                 * of following in ConnectionResult: SUCCESS, SERVICE_MISSING,
                 * SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID.
                 */
                Log.e(TAG, "---Google Play Services is not available: "
                        + GooglePlayServicesUtil.getErrorString(checkGooglePlayServices));

                boolean isNeedToUpdate = false;

                String errorMsg = "Google Maps Android API v2 is not available for some reason on this device. Do you install the latest Google Play Services from Google Play Store?";
                switch (checkGooglePlayServices) {
                case ConnectionResult.DEVELOPER_ERROR:
                    errorMsg = "The application is misconfigured. This error is not recoverable and will be treated as fatal. The developer should look at the logs after this to determine more actionable information.";
                    break;
                case ConnectionResult.INTERNAL_ERROR:
                    errorMsg = "An internal error of Google Play Services occurred. Please retry, and it should resolve the problem.";
                    break;
                case ConnectionResult.INVALID_ACCOUNT:
                    errorMsg = "You attempted to connect to the service with an invalid account name specified.";
                    break;
                case ConnectionResult.LICENSE_CHECK_FAILED:
                    errorMsg = "The application is not licensed to the user. This error is not recoverable and will be treated as fatal.";
                    break;
                case ConnectionResult.NETWORK_ERROR:
                    errorMsg = "A network error occurred. Please retry, and it should resolve the problem.";
                    break;
                case ConnectionResult.SERVICE_DISABLED:
                    errorMsg = "The installed version of Google Play services has been disabled on this device. Please turn on Google Play Services.";
                    break;
                case ConnectionResult.SERVICE_INVALID:
                    errorMsg = "The version of the Google Play services installed on this device is not authentic. Please update the Google Play Services from Google Play Store.";
                    isNeedToUpdate = true;
                    break;
                case ConnectionResult.SERVICE_MISSING:
                    errorMsg = "Google Play services is missing on this device. Please install the Google Play Services.";
                    isNeedToUpdate = true;
                    break;
                case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
                    errorMsg = "The installed version of Google Play services is out of date. Please update the Google Play Services from Google Play Store.";
                    isNeedToUpdate = true;
                    break;
                case ConnectionResult.SIGN_IN_REQUIRED:
                    errorMsg = "You attempted to connect to the service but you are not signed in. Please check the Google Play Services configuration";
                    break;
                default:
                    isNeedToUpdate = true;
                    break;
                }

                final boolean finalIsNeedToUpdate = isNeedToUpdate;
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
                alertDialogBuilder.setMessage(errorMsg).setCancelable(false).setPositiveButton("Close",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                                if (finalIsNeedToUpdate) {
                                    try {
                                        activity.startActivity(new Intent(Intent.ACTION_VIEW,
                                                Uri.parse("market://details?id=com.google.android.gms")));
                                    } catch (android.content.ActivityNotFoundException anfe) {
                                        activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                                                "http://play.google.com/store/apps/details?id=appPackageName")));
                                    }
                                }
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();

                Log.e(TAG, "Google Play Services is not available.");
                return;
            }

            webView.getView().setBackgroundColor(Color.TRANSPARENT);
            webView.getView().setOverScrollMode(View.OVER_SCROLL_NEVER);
            mPluginLayout = new MyPluginLayout(webView, activity);

            // Check the API key
            ApplicationInfo appliInfo = null;
            try {
                appliInfo = activity.getPackageManager().getApplicationInfo(activity.getPackageName(),
                        PackageManager.GET_META_DATA);
            } catch (NameNotFoundException e) {
            }

            String API_KEY = appliInfo.metaData.getString("com.google.android.maps.v2.API_KEY");
            if ("API_KEY_FOR_ANDROID".equals(API_KEY)) {

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);

                alertDialogBuilder.setMessage(
                        "Please replace 'API_KEY_FOR_ANDROID' in the platforms/android/AndroidManifest.xml with your API Key!")
                        .setCancelable(false).setPositiveButton("Close", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();
            }

            CURRENT_URL = webView.getUrl();

            //------------------------------
            // Initialize Google Maps SDK
            //------------------------------
            if (!initialized) {
                try {
                    MapsInitializer.initialize(cordova.getActivity());
                    initialized = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }
    });

}

From source file:org.wso2.iot.agent.api.ApplicationManager.java

/**
 * Returns a list of all the applications installed on the device by user.
 *
 * @return - List of applications which installed on the device by user.
 *//*from w w  w  . j  a v a  2 s .c  o  m*/
public List<String> getInstalledAppsByUser() {
    List<String> packagesInstalledByUser = new ArrayList<>();
    int flags = PackageManager.GET_META_DATA;
    List<ApplicationInfo> applications = packageManager.getInstalledApplications(flags);
    for (ApplicationInfo appInfo : applications) {
        if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 1) {
            packagesInstalledByUser.add(appInfo.packageName);
        }
    }
    return packagesInstalledByUser;
}

From source file:com.hao.common.manager.AppManager.java

/**
 * ???/*from   w  ww  .j  a v  a2  s.  c o m*/
 *
 * @return
 */
private String getChannel() {
    try {
        ApplicationInfo appInfo = sApp.getPackageManager().getApplicationInfo(sApp.getPackageName(),
                PackageManager.GET_META_DATA);
        return appInfo.metaData.getString("UMENG_CHANNEL");
    } catch (Exception e) {
        return "";
    }
}

From source file:com.youku.player.base.YoukuBasePlayerActivity.java

/**
 * ?YoukuPlayersetIEncryptVideoCallBack?
 * YoukuBasePlayerActivity??call???/*from w  ww  .j av  a  2 s.  c om*/
 */
//   public boolean isApiServiceAvailable = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
    Logger.d("PlayFlow", "YoukuBasePlayerActivity->onCreate");
    if (DEVELOPER_MODE) {
        StrictMode.setThreadPolicy(
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // ??detectAll()
                        // ?I/O
                        .penaltyLog() // ?logcat??dropbox?log
                        .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() // SQLite???
                .penaltyLog() // ?logcat
                .penaltyDeath().build());
    }

    super.onCreate(savedInstanceState);
    /*      isApiServiceAvailable = PlayerUiUtile.isYoukuPlayerServiceAvailable(this);
            if(!isApiServiceAvailable){
             return;
          }
            
          PlayerUiUtile.initialYoukuPlayerService(this);
          mediaPlayerDelegate = RemoteInterface.mediaPlayerDelegate;*/

    if (mCreateTime == 0) {
        // ????
        Profile.getVideoQualityFromSharedPreferences(getApplicationContext());
    }
    ++mCreateTime;
    youkuContext = this;
    mImageWorker = (ImageResizer) getImageWorker(this);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    OfflineStatistics offline = new OfflineStatistics();
    offline.sendVV(this);

    ACTIVE_TIME = PreferenceUtil.getPreference(this, "active_time");
    if (ACTIVE_TIME == null || ACTIVE_TIME.length() == 0) {
        ACTIVE_TIME = String.valueOf(System.currentTimeMillis());
        PreferenceUtil.savePreference(this, "active_time", ACTIVE_TIME);
    }

    // ??
    Profile.GUID = Device.guid;
    try {
        YoukuBasePlayerActivity.versionName = getPackageManager().getPackageInfo(getPackageName(),
                PackageManager.GET_META_DATA).versionName;
    } catch (NameNotFoundException e) {
        YoukuBasePlayerActivity.versionName = "3.1";
        Logger.e(TAG_GLOBAL, e);
    }

    if (TextUtils.isEmpty(com.baseproject.utils.Profile.User_Agent)) {
        String plant = UIUtils.isTablet(this) ? "Youku HD;" : "Youku;";
        com.baseproject.utils.Profile.initProfile("player", plant + versionName + ";Android;"
                + android.os.Build.VERSION.RELEASE + ";" + android.os.Build.MODEL, getApplicationContext());
    }

    //      mApplication = PlayerApplication.getPlayerApplicationInstance();
    flags = getApplicationInfo().flags;
    com.baseproject.utils.Profile.mContext = getApplicationContext();
    if (MediaPlayerProxyUtil.isUplayerSupported()) { //-------------------->
        YoukuBasePlayerActivity.isHighEnd = true;
        // 
        PreferenceUtil.savePreference(this, "isSoftwareDecode", true);
        com.youku.player.goplay.Profile
                .setVideoType_and_PlayerType(com.youku.player.goplay.Profile.FORMAT_FLV_HD, this);
    } else {
        YoukuBasePlayerActivity.isHighEnd = false;
        com.youku.player.goplay.Profile
                .setVideoType_and_PlayerType(com.youku.player.goplay.Profile.FORMAT_3GPHD, this);
    }

    IMediaPlayerDelegate.is = getResources().openRawResource(R.raw.aes); //-------------------------------------->
    orientationHelper = new DeviceOrientationHelper(this, this);
}

From source file:org.mozilla.gecko.GeckoApp.java

String[] getPluginDirectories() {
    // we don't support Honeycomb
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            && Build.VERSION.SDK_INT < 14 /*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ )
        return new String[0];

    Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - start of getPluginDirectories");

    ArrayList<String> directories = new ArrayList<String>();
    PackageManager pm = mAppContext.getPackageManager();
    List<ResolveInfo> plugins = pm.queryIntentServices(new Intent(PLUGIN_ACTION),
            PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);

    synchronized (mPackageInfoCache) {

        // clear the list of existing packageInfo objects
        mPackageInfoCache.clear();//  w  w w  .  ja  va  2  s  .  c  o m

        for (ResolveInfo info : plugins) {

            // retrieve the plugin's service information
            ServiceInfo serviceInfo = info.serviceInfo;
            if (serviceInfo == null) {
                Log.w(LOGTAG, "Ignore bad plugin");
                continue;
            }

            // Blacklist HTC's flash lite.
            // See bug #704516 - We're not quite sure what Flash Lite does,
            // but loading it causes Flash to give errors and fail to draw.
            if (serviceInfo.packageName.equals("com.htc.flashliteplugin")) {
                Log.w(LOGTAG, "Skipping HTC's flash lite plugin");
                continue;
            }

            Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName);

            // retrieve information from the plugin's manifest
            PackageInfo pkgInfo;
            try {
                pkgInfo = pm.getPackageInfo(serviceInfo.packageName,
                        PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES);
            } catch (Exception e) {
                Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
                continue;
            }
            if (pkgInfo == null) {
                Log.w(LOGTAG,
                        "Loading plugin: " + serviceInfo.packageName + ". Could not load package information.");
                continue;
            }

            /*
             * find the location of the plugin's shared library. The default
             * is to assume the app is either a user installed app or an
             * updated system app. In both of these cases the library is
             * stored in the app's data directory.
             */
            String directory = pkgInfo.applicationInfo.dataDir + "/lib";
            final int appFlags = pkgInfo.applicationInfo.flags;
            final int updatedSystemFlags = ApplicationInfo.FLAG_SYSTEM
                    | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
            // preloaded system app with no user updates
            if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) {
                directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName;
            }

            // check if the plugin has the required permissions
            String permissions[] = pkgInfo.requestedPermissions;
            if (permissions == null) {
                Log.w(LOGTAG,
                        "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission.");
                continue;
            }
            boolean permissionOk = false;
            for (String permit : permissions) {
                if (PLUGIN_PERMISSION.equals(permit)) {
                    permissionOk = true;
                    break;
                }
            }
            if (!permissionOk) {
                Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName
                        + ". Does not have required permission (2).");
                continue;
            }

            // check to ensure the plugin is properly signed
            Signature signatures[] = pkgInfo.signatures;
            if (signatures == null) {
                Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Not signed.");
                continue;
            }

            // determine the type of plugin from the manifest
            if (serviceInfo.metaData == null) {
                Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined");
                continue;
            }

            String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE);
            if (!TYPE_NATIVE.equals(pluginType)) {
                Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType);
                continue;
            }

            try {
                Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name);

                //TODO implement any requirements of the plugin class here!
                boolean classFound = true;

                if (!classFound) {
                    Log.e(LOGTAG, "The plugin's class' " + serviceInfo.name
                            + "' does not extend the appropriate class.");
                    continue;
                }

            } catch (NameNotFoundException e) {
                Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
                continue;
            } catch (ClassNotFoundException e) {
                Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name);
                continue;
            }

            // if all checks have passed then make the plugin available
            mPackageInfoCache.add(pkgInfo);
            directories.add(directory);
        }
    }

    String[] result = directories.toArray(new String[directories.size()]);
    Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - end of getPluginDirectories");
    return result;
}

From source file:com.androidzeitgeist.dashwatch.dashclock.ExtensionManager.java

/**
 * Returns a listing of all available (installed) extensions.
 */// www . j  a  v  a  2 s  . co  m
public List<ExtensionListing> getAvailableExtensions() {
    List<ExtensionListing> availableExtensions = new ArrayList<ExtensionListing>();
    PackageManager pm = mApplicationContext.getPackageManager();
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(new Intent(DashClockExtension.ACTION_EXTENSION),
            PackageManager.GET_META_DATA);
    for (ResolveInfo resolveInfo : resolveInfos) {
        ExtensionListing listing = new ExtensionListing();
        listing.componentName = new ComponentName(resolveInfo.serviceInfo.packageName,
                resolveInfo.serviceInfo.name);
        listing.title = resolveInfo.loadLabel(pm).toString();
        Bundle metaData = resolveInfo.serviceInfo.metaData;
        if (metaData != null) {
            listing.protocolVersion = metaData.getInt("protocolVersion");
            listing.worldReadable = metaData.getBoolean("worldReadable", false);
            listing.description = metaData.getString("description");
            String settingsActivity = metaData.getString("settingsActivity");
            if (!TextUtils.isEmpty(settingsActivity)) {
                listing.settingsActivity = ComponentName
                        .unflattenFromString(resolveInfo.serviceInfo.packageName + "/" + settingsActivity);
            }
        }

        listing.icon = resolveInfo.loadIcon(pm);
        availableExtensions.add(listing);
    }

    return availableExtensions;
}

From source file:fr.inria.ucn.Helpers.java

/**
 * Check for the OpenVPN for Android app:
 * https://play.google.com/store/apps/details?id=de.blinkt.openvpn
 * @param c/*w  w  w . ja v  a 2s .c om*/
 * @return
 */
public static boolean isOpenVPNClientInstalled(Context c) {
    boolean res = false;
    PackageManager pm = c.getPackageManager();
    for (ApplicationInfo ai : pm.getInstalledApplications(PackageManager.GET_META_DATA)) {
        if (ai.packageName.contains("de.blinkt.openvpn")) {
            res = true;
            break;
        }
    }
    return res;
}