List of usage examples for android.content.pm PackageManager GET_ACTIVITIES
int GET_ACTIVITIES
To view the source code for android.content.pm PackageManager GET_ACTIVITIES.
Click Source Link
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 w w . j a va2 s . co 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.lovejoy777sarootool.rootool.preview.IconPreview.java
private static Bitmap getPreview(File file) { final boolean isImage = MimeTypes.isPicture(file); final boolean isVideo = MimeTypes.isVideo(file); final boolean isApk = file.getName().endsWith(".apk"); Bitmap mBitmap = null;/*from www . j av a 2 s .c om*/ String path = file.getAbsolutePath(); if (isImage) { BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, o); o.inJustDecodeBounds = false; if (o.outWidth != -1 && o.outHeight != -1) { final int originalSize = (o.outHeight > o.outWidth) ? o.outWidth : o.outHeight; o.inSampleSize = originalSize / mWidth; } mBitmap = BitmapFactory.decodeFile(path, o); cache.put(path, mBitmap); return mBitmap; } else if (isVideo) { mBitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MICRO_KIND); cache.put(path, mBitmap); return mBitmap; } else if (isApk) { final PackageInfo packageInfo = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES); if (packageInfo != null) { final ApplicationInfo appInfo = packageInfo.applicationInfo; if (appInfo != null) { appInfo.sourceDir = path; appInfo.publicSourceDir = path; final Drawable icon = appInfo.loadIcon(pm); if (icon != null) { mBitmap = ((BitmapDrawable) icon).getBitmap(); } } } else { // load apk icon from /res/drawable/.. mBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.type_apk); } cache.put(path, mBitmap); return mBitmap; } return null; }
From source file:org.wso2.app.catalog.api.ApplicationManager.java
public boolean isPackageInstalled(String packagename) { try {/*from w w w . j a v a2s . c o m*/ PackageInfo packageInfo = packageManager.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES); if (packageInfo != null) { return true; } } catch (PackageManager.NameNotFoundException e) { return false; } return false; }
From source file:cn.whereyougo.framework.utils.PackageManagerUtil.java
/** * apk?// www . ja v a 2 s . co m * * @return truefalse */ public static boolean checkApkIsInstalled(Context context, String packageName) { boolean result = false; try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); if (packageInfo != null) { result = true; } } catch (NameNotFoundException e) { LogUtil.e(TAG, TAG + "--->Exception:" + e.getMessage()); } return result; }
From source file:io.ionic.links.IonicDeeplink.java
/** * Check if we can open an app with a given URI scheme. * * Thanks to https://github.com/ohh2ahh/AppAvailability/blob/master/src/android/AppAvailability.java *///from w ww.j ava 2s. co m private void canOpenApp(String uri, final CallbackContext callbackContext) { Context ctx = this.cordova.getActivity().getApplicationContext(); final PackageManager pm = ctx.getPackageManager(); try { pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES); callbackContext.success(); } catch (PackageManager.NameNotFoundException e) { } callbackContext.error(""); }
From source file:io.github.pwlin.cordova.plugins.fileopener2.FileOpener2.java
private boolean _appIsInstalled(String packageId) { PackageManager pm = cordova.getActivity().getPackageManager(); boolean appInstalled = false; try {// w w w.j av a 2s. co m pm.getPackageInfo(packageId, PackageManager.GET_ACTIVITIES); appInstalled = true; } catch (PackageManager.NameNotFoundException e) { appInstalled = false; } return appInstalled; }
From source file:org.cyanogenmod.theme.chooser.ChooserBrowseFragment.java
private boolean isThemeStoreInstalled() { PackageManager pm = getActivity().getPackageManager(); try {//from w w w . j a va 2 s . c om pm.getPackageInfo(THEME_STORE_PACKAGE_NAME, PackageManager.GET_ACTIVITIES); return true; } catch (NameNotFoundException e) { return false; } }
From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java
@Override Object getEntries(Context context) { PackageManager pm = context.getPackageManager(); int requestedPackageInfoFlags = type | PackageManager.GET_DISABLED_COMPONENTS | (requireMetaDataSubstring != null ? PackageManager.GET_META_DATA : 0); boolean workAroundSmallBinderBuffer = false; List<PackageInfo> allPackages = null; try {/*from www . j a v a 2 s .c o m*/ allPackages = pm.getInstalledPackages(requestedPackageInfoFlags); } catch (Exception e) { Log.w(TAG, "Loading all apps at once failed, retrying separately", e); } if (allPackages == null || allPackages.isEmpty()) { workAroundSmallBinderBuffer = true; allPackages = pm.getInstalledPackages(0); } ArrayList<Category> selectedApps = new ArrayList<Category>(); for (PackageInfo pack : allPackages) { // Filter out non-applications if (pack.applicationInfo == null) { continue; } // System app filter if ((((pack.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0 ? APP_TYPE_SYSTEM : APP_TYPE_USER) & appType) == 0) { continue; } // Load component information separately if they were to big to send them all at once if (workAroundSmallBinderBuffer) { try { pack = pm.getPackageInfo(pack.packageName, requestedPackageInfoFlags); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, "getPackageInfo() thrown NameNotFoundException for " + pack.packageName, e); continue; } } // Scan components ArrayList<Component> selectedComponents = new ArrayList<Component>(); if ((type & PackageManager.GET_ACTIVITIES) != 0) { scanComponents(pm, pack.activities, selectedComponents); } if ((type & PackageManager.GET_RECEIVERS) != 0) { scanComponents(pm, pack.receivers, selectedComponents); } if ((type & PackageManager.GET_SERVICES) != 0) { scanComponents(pm, pack.services, selectedComponents); } if ((type & PackageManager.GET_PROVIDERS) != 0) { scanComponents(pm, pack.providers, selectedComponents); } // Check if we filtered out all components and skip whole app if so if (selectedComponents.isEmpty()) { continue; } // Build and add app descriptor Category app = new Category(); app.title = String.valueOf(pack.applicationInfo.loadLabel(pm)); app.subtitle = pack.packageName; app.components = selectedComponents.toArray(new Component[selectedComponents.size()]); selectedApps.add(app); // Allow cancelling task if (Thread.interrupted()) { return null; } } return selectedApps.toArray(new Category[selectedApps.size()]); }
From source file:com.etalio.android.EtalioBase.java
private boolean isEtalioInstalled(Context context) { PackageManager pm = context.getPackageManager(); try {// w w w. j a v a 2 s. co m pm.getPackageInfo("com.etalio.android", PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:com.dunrite.now.MainActivity.java
public boolean isAppInstalled(String packageName) { PackageManager pm = getPackageManager(); boolean installed = false; try {// w ww.j a v a 2s .c o m pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES); installed = true; } catch (PackageManager.NameNotFoundException e) { installed = false; } return installed; }