Example usage for android.app Activity getPackageManager

List of usage examples for android.app Activity getPackageManager

Introduction

In this page you can find the example usage for android.app Activity getPackageManager.

Prototype

@Override
    public PackageManager getPackageManager() 

Source Link

Usage

From source file:Main.java

public static boolean testingShowWebView(final Activity activity, final String aid, final String url) {
    if (TextUtils.isEmpty(url)) {
        Intent intent = new Intent(adWebAction);
        intent.putExtra("aid", aid);
        if (intent.resolveActivity(activity.getPackageManager()) != null) {
            activity.startActivity(intent);
        }//from  w  w  w .jav  a2 s  . c om
        return true;
    }

    return false;
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.TextLineWidget.java

private static boolean isSpeechRecognitionActivityPresented(Activity callerActivity) {
    try {//from www. j a v  a  2  s .c o m
        PackageManager pm = callerActivity.getPackageManager();
        List<ResolveInfo> activities = pm
                .queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);

        if (activities.size() != 0) {
            return true;
        }
    } catch (Exception e) {
        L.bug(e);
    }
    return false;
}

From source file:com.nuvolect.securesuite.util.PermissionUtil.java

/**
 * Request permissions during application first time install.
 * Method will not ask for phone state if it is not a phone.
 * @param act// w ww.  j  a va2s .c o  m
 */
public static void requestFirstTimePermissions(Activity act) {

    ArrayList<String> permissionRequests = new ArrayList<String>();
    PackageManager pm = act.getPackageManager();

    if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {

        if (!hasPermission(act, android.Manifest.permission.READ_PHONE_STATE)) {

            permissionRequests.add(Manifest.permission.READ_PHONE_STATE);
        }
    }
    if (!hasPermission(act, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

        permissionRequests.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }

    if (permissionRequests.size() > 0) {

        String[] requests = new String[permissionRequests.size()];
        requests = permissionRequests.toArray(requests);
        ActivityCompat.requestPermissions(act, requests, CConst.NO_ACTION);
    }
}

From source file:org.totschnig.myexpenses.activity.CommonCommands.java

/**
 * @return version number (versionCode)//from   www  . jav a  2s.c  o m
 */
public static int getVersionNumber(Activity ctx) {
    int version = -1;
    try {
        PackageInfo pi = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
        version = pi.versionCode;
    } catch (Exception e) {
        Log.e("MyExpenses", "Package name not found", e);
    }
    return version;
}

From source file:org.totschnig.myexpenses.activity.CommonCommands.java

/**
 * @return version name/*  w  w w  .jav  a2  s  .  co  m*/
 */
public static String getVersionName(Activity ctx) {
    String version = "";
    try {
        PackageInfo pi = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
        version = pi.versionName;
    } catch (Exception e) {
        Log.e("MyExpenses", "Package name not found", e);
    }
    return version;
}

From source file:Main.java

public static void getAuthorityFromPermission(Activity context) {
    String read_settings = "com.android.launcher.permission.READ_SETTINGS";
    String write_settings = "com.android.launcher.permission.WRITE_SETTINGS";
    List<PackageInfo> packs = context.getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS);
    if (packs != null) {
        for (PackageInfo pack : packs) {
            ProviderInfo[] providers = pack.providers;
            if (providers != null) {
                for (ProviderInfo provider : providers) {
                    if ((read_settings.equals(provider.readPermission)
                            || (write_settings.equals(provider.writePermission)))) {
                        Toast.makeText(context, pack.applicationInfo.packageName, Toast.LENGTH_LONG).show();
                        if (isExistShortcut(context, provider.authority)) {
                            continue;
                        } else {
                            /*
                             * ShotcutUtil.createShortcut(context, SplashActivity.class,
                             * R.string.app_name, R.drawable.icon, false);
                             *///ww  w  . ja  v a  2  s .  c om
                            continue;

                        }

                    }
                }
            }
        }
    }
    return;
}

From source file:org.totschnig.myexpenses.activity.CommonCommands.java

/**
 * retrieve information about the current version
 * @return concatenation of versionName, versionCode and buildTime
 * buildTime is automatically stored in property file during build process
 *///from   www  .  jav  a  2  s. co m
public static String getVersionInfo(Activity ctx) {
    String version = "";
    String versionname = "";
    try {
        PackageInfo pi = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
        version = " (revision " + pi.versionCode + ") ";
        versionname = pi.versionName;
        //versiontime = ", " + R.string.installed + " " + sdf.format(new Date(pi.lastUpdateTime));
    } catch (Exception e) {
        Log.e(MyApplication.TAG, "Package info not found", e);
    }
    String buildDate = BuildConfig.BUILD_DATE;

    final String flavor = TextUtils.isEmpty(BuildConfig.FLAVOR) ? "" : " " + BuildConfig.FLAVOR;
    String installer = ctx.getPackageManager().getInstallerPackageName(ctx.getPackageName());
    installer = TextUtils.isEmpty(installer) ? "" : " " + installer;
    return versionname + version + buildDate + flavor + installer;
}

From source file:Main.java

public static Boolean isActionAvailable(Activity activity, int action) {
    Log.d(TAG, "[AirImagePickerUtils] Entering isActionAvailable");
    if (action == CROP_ACTION) {
        return isCropAvailable(activity);
    }/*  w w  w . j ava2 s.  co m*/

    final PackageManager packageManager = activity.getPackageManager();
    List<ResolveInfo> list = packageManager.queryIntentActivities(getIntentForAction(action),
            PackageManager.MATCH_DEFAULT_ONLY);

    Log.d(TAG, "[AirImagePickerUtils] Exiting isActionAvailable");

    return list.size() > 0;
}

From source file:com.github.piasy.safelyandroid.activity.StartActivityDelegate.java

/**
 * start activity for result from {@link Activity}
 *
 * @param activity activity we start from
 * @param intent intent to start/*w  ww  .  ja v a 2  s.c o m*/
 * @param requestCode request code
 * @param options options used to start activity
 * @return {@code true} if we start it safely, {@code false} if it's unsafe so we didn't start
 * it
 */
public static boolean startActivityForResultSafely(@NonNull Activity activity, @NonNull Intent intent,
        int requestCode, Bundle options) {
    if (isIntentSafe(activity.getPackageManager(), intent)) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            activity.startActivityForResult(intent, requestCode, options);
        } else {
            activity.startActivityForResult(intent, requestCode);
        }
        return true;
    }
    return false;
}

From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java

public static void showPictureLauncher(final Activity activity, final ClearImageCallback clearImageOption) {
    ArrayList<String> options = new ArrayList<String>();

    final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager pm = activity.getPackageManager();

    final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0;
    if (cameraAvailable)
        options.add(activity.getString(R.string.actfm_picture_camera));
    options.add(activity.getString(R.string.actfm_picture_gallery));

    if (clearImageOption != null)
        options.add(activity.getString(R.string.actfm_picture_clear));

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()]));

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @SuppressWarnings("nls")
        @Override// w w w  .j ava  2  s. co  m
        public void onClick(DialogInterface d, int which) {
            if (which == 0 && cameraAvailable) {
                lastTempFile = getTempFile(activity);
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (lastTempFile != null) {
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile));
                }
                activity.startActivityForResult(intent, REQUEST_CODE_CAMERA);
            } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                activity.startActivityForResult(
                        Intent.createChooser(intent, activity.getString(R.string.actfm_TVA_tag_picture)),
                        REQUEST_CODE_PICTURE);
            } else {
                if (clearImageOption != null)
                    clearImageOption.clearImage();
            }
        }
    };

    // show a menu of available options
    new AlertDialog.Builder(activity).setAdapter(adapter, listener).show().setOwnerActivity(activity);
}