Android Utililty Methods APK Installation Check

List of utility methods to do APK Installation Check

Description

The list of methods to do APK Installation Check are organized into topic(s).

Method

booleanisAppInstalled(Context ctx, String uri)
is App Installed
PackageManager pm = ctx.getPackageManager();
boolean installed = false;
try {
    pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
    installed = true;
} catch (PackageManager.NameNotFoundException e) {
    installed = false;
return installed;
booleanisApkInstalled(Context context, String packageName)
is Apk Installed
PackageInfo packageInfo = null;
try {
    packageInfo = context.getPackageManager().getPackageInfo(
            packageName, PackageManager.GET_ACTIVITIES);
} catch (NameNotFoundException e) {
    packageInfo = null;
    e.printStackTrace();
if (packageInfo == null) {
    return false;
} else {
    Log.e(TAG, packageInfo.toString());
    return true;
voidinstallApk(Context context, File file)
install Apk
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
        "application/vnd.android.package-archive");
context.startActivity(intent);
voidinstallApk(Context context, File file)
install Apk
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
        "application/vnd.android.package-archive");
context.startActivity(intent);
voiduninstallApk(Context context, String packageName)
uninstall Apk
Intent intent = new Intent(Intent.ACTION_DELETE);
Uri packageURI = Uri.parse("package:" + packageName);
intent.setData(packageURI);
context.startActivity(intent);
booleanverifySampleSetup(Activity activity, int... resIds)
For use in sample code only.
StringBuilder problems = new StringBuilder();
boolean problemFound = false;
problems.append("The following set up problems were found:\n\n");
if (activity.getPackageName()
        .startsWith("com.google.example.games")) {
    problemFound = true;
    problems.append(
            "- Package name cannot be com.google.*. You need to change the "
...
voidinstallWatchapp(final Activity parent, final String pbwFilename, final String appstoreUid)
Let use choose install source for 2.0 use
AlertDialog.Builder dialog = new AlertDialog.Builder(parent);
dialog.setTitle("Choose Install Method");
dialog.setMessage("Choose 'Pebble Appstore' if you are using 2.0 BETA 9+, else choose 'Local .pbw'.");
dialog.setPositiveButton("Local .pbw",
        new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(parent,
...