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:es.glasspixel.wlanaudit.activities.AboutActivity.java

private int getRelease() {
    int release = -1;
    try {//from  w ww . ja v a 2s .c o m
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
        release = pInfo.versionCode;
    } catch (NameNotFoundException e1) {
        Log.e(this.getClass().getSimpleName(), "Name not found", e1);
    }
    return release;
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    sharedPref = this.getSharedPreferences("PODEMU_PREFS", Context.MODE_PRIVATE);

    //String[] controlledApp = new String[appsRunning.size()];
    //Drawable[] icons = new Drawable[appsRunning.size()];
    //pm.getApplicationInfo(r.baseActivity.getPackageName(), PackageManager.GET_META_DATA);
    //Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //startActivity(intent);

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_APP_MUSIC);

    PackageManager pm = getPackageManager();
    String text = "";
    List<ResolveInfo> packages = pm.queryIntentActivities(intent, 0);
    //get a list of installed apps.
    //List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    //using hashset so that there will be no duplicate packages,
    //if no duplicate packages then there will be no duplicate apps
    HashSet<String> packageNames = new HashSet<String>(0);
    appInfos = new ArrayList<ApplicationInfo>(0);

    //getting package names and adding them to the hashset
    for (ResolveInfo resolveInfo : packages) {
        packageNames.add(resolveInfo.activityInfo.packageName);
    }//  w w w . java  2 s  .  c o m

    // used just for tests
    /*
    ApplicationInfo dummyApp = new ApplicationInfo();
    dummyApp.name="select application";
    dummyApp.processName="dummy";
    appInfos.add(dummyApp);
    */

    for (String packageName : PodEmuIntentFilter.getAppList()) {
        try {
            appInfos.add(pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA));
        } catch (PackageManager.NameNotFoundException e) {
            //Do Nothing
        }
    }
    //now we have unique packages in the hashset, so get their application infos
    //and add them to the arraylist
    for (String packageName : packageNames) {
        try {
            appInfos.add(pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA));

        } catch (PackageManager.NameNotFoundException e) {
            //Do Nothing
        }
    }

    text += "Apps count: " + appInfos.size() + "\n";
    for (ApplicationInfo appInfo : appInfos) {
        //if (packageInfo.)
        {
            appInfo.name = (String) appInfo.loadLabel(pm);
            text += appInfo.loadLabel(pm) + "\n";
            //text += packageInfo.
            //text += "\n";
        }
    }

    //TextView textView = (TextView) findViewById(R.id.ctrlAppTitle);
    //textView.setText(text);

    //LauncherApps launcherApps=new LauncherApps();
    //List<LauncherActivityInfo> activities=launcherApps.getActivityList(null, android.os.Process.myUserHandle());
    //List<LauncherActivityInfo> activities=LauncherApps().getActivityList(null, android.os.Process.myUserHandle());

    baudRateList.add(9600);
    baudRateList.add(14400);
    baudRateList.add(19200);
    baudRateList.add(28800);
    baudRateList.add(38400);
    baudRateList.add(56000);
    baudRateList.add(57600);
    baudRateList.add(115200);

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        String version = pInfo.versionName;
        TextView versionHint = (TextView) findViewById(R.id.versionHint);
        versionHint.setText(getResources().getString(R.string.version_hint) + version);
    } catch (PackageManager.NameNotFoundException e) {
        // do nothing
    }

}

From source file:com.jungle.base.utils.MiscUtils.java

public static String getMetaData(String metaKey) {
    Context context = BaseApplication.getAppContext();
    try {/*from  www. ja va  2  s. c o  m*/
        ApplicationInfo info = context.getPackageManager().getApplicationInfo(context.getPackageName(),
                PackageManager.GET_META_DATA);
        if (info.metaData != null && info.metaData.containsKey(metaKey)) {
            Object value = info.metaData.get(metaKey);
            return value != null ? value.toString() : null;
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.intel.xdk.base.Base.java

public void showSplashScreen() {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            //treat displays larger than 6" as tablets
            DisplayMetrics dm = new DisplayMetrics();
            cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
            double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
            double screenInches = Math.sqrt(x + y);
            if (screenInches > 6) {
                isTablet = true;/*from  w  ww. j a va  2 s.c  o m*/
            }

            //used for calculating status bar height
            int deviceWidth = dm.widthPixels;
            int deviceHeight = dm.heightPixels;
            if (deviceWidth > deviceHeight) {
                deviceWidth = dm.heightPixels;
                deviceHeight = dm.widthPixels;
            }

            //get the splash screen image from asssets
            Bitmap bm = null;
            try {
                if (isTablet) {
                    bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen_tablet.jpg");
                } else {
                    bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen.jpg");
                }
            } catch (IOException ioe) {
            }

            //if the splash screen assets are missing, don't try to show the splash screen
            if (bm == null) {
                return;
            }

            if (Debug.isDebuggerConnected())
                Log.i("[intel.xdk]", "splash");

            ActivityInfo ai = null;
            int splashViewId = 0;
            try {
                ai = cordova.getActivity().getPackageManager().getActivityInfo(
                        cordova.getActivity().getComponentName(),
                        PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);

                if (isTablet) {
                    if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet_ls",
                                "layout", cordova.getActivity().getPackageName());
                    } else {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet",
                                "layout", cordova.getActivity().getPackageName());
                    }
                } else {
                    if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_ls", "layout",
                                cordova.getActivity().getPackageName());
                    } else {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash", "layout",
                                cordova.getActivity().getPackageName());
                    }
                }
                LayoutInflater inflater = LayoutInflater.from(cordova.getActivity());
                splashView = inflater.inflate(splashViewId, null);

                //set the splash screen image
                //http://stackoverflow.com/questions/7776445/in-android-can-i-use-image-from-assets-in-layout-xml
                ImageView backgroundImage = (ImageView) splashView
                        .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id",
                                cordova.getActivity().getPackageName()));
                backgroundImage.setImageBitmap(bm);
                ((ViewGroup) root.getParent()).addView(splashView);
                splashView.bringToFront();

                //hack to fix splash screen size when it is smaller than screen            
                ImageView splashImage = (ImageView) cordova.getActivity()
                        .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id",
                                cordova.getActivity().getPackageName()));
                LayoutParams params = splashImage.getLayoutParams();
                Rect imgBounds = splashImage.getDrawable().getBounds();
                int splashHeight = params.height;
                int splashWidth = params.width;

                //make copies in case we have to switch for landscape - not sure if needed, this is a last minute hack
                int deviceWidthCopy, deviceHeightCopy;
                deviceWidthCopy = deviceWidth;
                deviceHeightCopy = deviceHeight;
                if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                    int temp = deviceWidthCopy;
                    deviceWidthCopy = deviceHeightCopy;
                    deviceHeightCopy = temp;
                }
                if (splashHeight < deviceHeightCopy || splashWidth < deviceWidthCopy) {
                    float scaleH = (float) deviceHeightCopy / splashHeight;
                    float scaleW = (float) deviceWidthCopy / splashWidth;
                    float scale = Math.max(scaleH, scaleW);
                    params.height *= scale;
                    params.width *= scale;
                    splashImage.setLayoutParams(params);
                }

                cordova.getActivity().setProgressBarIndeterminateVisibility(true);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}

From source file:com.apptentive.android.sdk.util.Util.java

public static Object getPackageMetaData(Context appContext, String key) {
    try {//from   w w w .  j  av  a 2 s  . c  o  m
        return appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(),
                PackageManager.GET_META_DATA).metaData.get(key);
    } catch (Exception e) {
        return null;
    }
}

From source file:qauth.djd.qauthclient.main.ContentFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Bundle args = getArguments();/*from ww w .j av  a 2s . c o  m*/
    if (args.getCharSequence(KEY_TITLE).toString().equals("Providers")) {

        View rootView = inflater.inflate(R.layout.providers_view_frag, container, false);

        mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
        mLayoutManager = new LinearLayoutManager(getActivity());
        mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;

        if (savedInstanceState != null) {
            // Restore saved layout manager type.
            mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState
                    .getSerializable(KEY_LAYOUT_MANAGER);
        }
        setRecyclerViewLayoutManager(mCurrentLayoutManagerType);

        pAdapter = new ProviderAdapter(pDataset);
        mRecyclerView.setAdapter(pAdapter);

        final PackageManager pm = getActivity().getPackageManager();
        List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

        for (ApplicationInfo packageInfo : packages) {
            //Log.i(TAG, "Installed package :" + packageInfo.packageName);
            //Log.i(TAG, "Source dir : " + packageInfo.sourceDir);
            //Log.i(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));

            if (packageInfo.packageName.equals("qauth.djd.dummyclient")) {
                Provider provider = new Provider("DummyClient", packageInfo.packageName);
                pDataset.add(provider);
                pAdapter.notifyDataSetChanged();
            }

        }

        //get local package names and cross reference with providers on server ("/provider/available")
        //display package names in listview
        //allow user to click on item to activate or deactivate
        // '-> have check box with progress bar indicating status

        return rootView;

    } else {

        View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false);
        mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
        mLayoutManager = new LinearLayoutManager(getActivity());
        mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;

        if (savedInstanceState != null) {
            // Restore saved layout manager type.
            mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState
                    .getSerializable(KEY_LAYOUT_MANAGER);
        }
        setRecyclerViewLayoutManager(mCurrentLayoutManagerType);

        wAdapter = new WatchAdapter(wDataset);
        mRecyclerView.setAdapter(wAdapter);

        FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
        fab.attachToRecyclerView(mRecyclerView);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("test", "clicked!");

                AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity());
                builderSingle.setIcon(R.drawable.ic_launcher);
                builderSingle.setTitle("Select Bluetooth Device");
                final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(),
                        android.R.layout.select_dialog_singlechoice);
                new Thread(new Runnable() {
                    public void run() {
                        for (String s : getNodes()) {
                            arrayAdapter.add(s);
                        }
                    }
                }).start();
                builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        String nodeId = arrayAdapter.getItem(which);
                        String privKey = null;
                        String pubKey = null;

                        try {
                            SecureRandom random = new SecureRandom();
                            RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024,
                                    RSAKeyGenParameterSpec.F4);
                            KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "SC");
                            generator.initialize(spec, random);
                            KeyPair pair = generator.generateKeyPair();
                            privKey = Base64.encodeToString(pair.getPrivate().getEncoded(), Base64.DEFAULT);
                            pubKey = Base64.encodeToString(pair.getPublic().getEncoded(), Base64.DEFAULT);
                        } catch (Exception e) {
                            Log.i("generate", "error: " + e);
                        }

                        //Log.i("keys", "priv key : " + privKey);

                        //String privKey = Base64.encodeToString(MainTabsActivity.privKey.getEncoded(), Base64.DEFAULT);
                        //String pubKey = Base64.encodeToString(MainTabsActivity.pubKey.getEncoded(), Base64.DEFAULT);

                        Keys keys = new Keys(privKey, pubKey);
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        ObjectOutput out = null;
                        try {
                            out = new ObjectOutputStream(bos);
                        } catch (Exception e) {
                        }
                        try {
                            out.writeObject(keys);
                        } catch (Exception e) {
                        }
                        byte b[] = bos.toByteArray();
                        try {
                            out.close();
                        } catch (Exception e) {
                        }
                        try {
                            bos.close();
                        } catch (Exception e) {
                        }

                        Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, "REGISTER", b)
                                .setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
                                    @Override
                                    public void onResult(MessageApi.SendMessageResult sendMessageResult) {
                                        if (!sendMessageResult.getStatus().isSuccess()) {
                                            Log.i("MessageApi", "Failed to send message with status code: "
                                                    + sendMessageResult.getStatus().getStatusCode());
                                        } else if (sendMessageResult.getStatus().isSuccess()) {
                                            Log.i("MessageApi", "onResult successful!");
                                        }
                                    }
                                });

                    }
                });
                builderSingle.show();

            }
        });

        mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addConnectionCallbacks(this)
                .addOnConnectionFailedListener(
                        new com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener() {
                            @Override
                            public void onConnectionFailed(ConnectionResult result) {
                                Log.i("mGoogleApiClient", "onConnectionFailed: " + result);
                            }
                        })
                // Request access only to the Wearable API
                .addApi(Wearable.API).build();
        mGoogleApiClient.connect();

        /*BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
                
        for(BluetoothDevice bt : pairedDevices)
        Log.i("BluetoothDevice", "pairedDevice: " + bt.toString());*/

        return rootView;

    }

}

From source file:de.madvertise.android.sdk.MadvertiseUtil.java

/**
 * Returns the madvertise token/*w  w  w.  jav a  2 s.c  om*/
 * 
 * @param context
 *            application context
 * @return madvertise_token from AndroidManifest.xml or null
 */
public static String getToken(final Context context, MadvertiseViewCallbackListener listener) {
    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) {
        MadvertiseUtil.logMessage(null, Log.DEBUG,
                "Could not fetch \"madvertise_site_token\" from AndroidManifest.xml");
        if (listener != null) {
            listener.onError(new IllegalArgumentException(
                    "Could not fetch \"madvertise_site_token\" from AndroidManifest.xml"));
        }
    }

    return madvertiseToken;
}

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

private boolean addAppToView(ShortcutDetail shortcut) {
    try {//w  ww  .  jav  a 2 s  .  co m
        ApplicationInfo appInfo = mPacMan.getApplicationInfo(shortcut.name, PackageManager.GET_META_DATA);
        AppDetail appDetail = new AppDetail();
        appDetail.label = mPacMan.getApplicationLabel(appInfo);

        // load the icon later in an async task
        appDetail.icon = null;

        appDetail.name = shortcut.name;
        appDetail.id = shortcut.id;

        appsList.add(appDetail);
        return true;

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

From source file:es.glasspixel.wlanaudit.activities.AboutActivity.java

private String getVersion() {
    String version = null;//w ww . j a v  a 2 s .co m
    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
        version = pInfo.versionName;
    } catch (NameNotFoundException e1) {
        Log.e(this.getClass().getSimpleName(), "Name not found", e1);
    }
    return version;
}