Example usage for android.content.pm PackageManager GET_ACTIVITIES

List of usage examples for android.content.pm PackageManager GET_ACTIVITIES

Introduction

In this page you can find the example usage for android.content.pm PackageManager GET_ACTIVITIES.

Prototype

int GET_ACTIVITIES

To view the source code for android.content.pm PackageManager GET_ACTIVITIES.

Click Source Link

Document

PackageInfo flag: return information about activities in the package in PackageInfo#activities .

Usage

From source file:com.uwt.strugglebus.geotracker.Controller.Eula.java

/**
 * Retrieves and returns the activity package info
 *///w  ww  .ja v  a2s. co m
private PackageInfo getPackageInfo() {
    PackageInfo pi = null;
    try {
        pi = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(),
                PackageManager.GET_ACTIVITIES);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return pi;
}

From source file:org.chromium.ChromePushMessaging.java

static public void handlePushMessage(Context context, Intent intent) {
    JSONObject payload = new JSONObject();
    try {/*w w  w .jav a  2 s .co m*/
        for (String key : intent.getExtras().keySet()) {
            payload.put(key, intent.getStringExtra(key));
        }
    } catch (Exception e) {
        Log.e(LOG_TAG, "Error construction push message payload: " + e);
        return;
    }
    String payloadString = payload.toString();
    if (webView == null) {
        try {
            String activityClass = context.getPackageManager().getPackageInfo(context.getPackageName(),
                    PackageManager.GET_ACTIVITIES).activities[0].name;
            Intent activityIntent = Intent.makeMainActivity(new ComponentName(context, activityClass));
            activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activityIntent.putExtra(PAYLOAD_LABEL, payloadString);
            pendingMessages.add(payloadString);
            context.startActivity(activityIntent);
        } catch (Exception e) {
            Log.e(LOG_TAG, "Failed to make startActivity intent: " + e);
        }
        return;
    }
    if (!safeToFireMessages) {
        pendingMessages.add(payloadString);
        return;
    }
    fireOnMessage(payloadString);
}

From source file:io.github.importre.android.chromeadb.InfoFragment.java

private void setVersion() {
    try {/*  www  . j  a v a2 s.c  om*/
        FragmentActivity activity = getActivity();
        PackageManager pm = activity.getPackageManager();
        PackageInfo info = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES);
        String ver = String.format(Locale.US, "%s (Build %d)", info.versionName, info.versionCode);
        mBtnVersion.setText(ver);
    } catch (Exception e) {
    }
}

From source file:uk.ac.hutton.ics.buntata.activity.ChangelogActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* Set the toolbar as the action bar */
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }//ww w.ja va  2 s. c o  m
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    }

    // Get the versionCode of the Package, which must be different (incremented) in each release on the market in the AndroidManifest.xml
    final PackageInfo packageInfo;
    try {
        packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
        PreferenceUtils.setPreferenceAsInt(ChangelogActivity.this, PreferenceUtils.PREFS_LAST_VERSION,
                packageInfo.versionCode);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:org.chromium.ChromeGcm.java

static public void startApp(Context context) {
    if (webView == null) {
        try {//from  www.  j  ava 2s.  c  o m
            String activityClass = context.getPackageManager().getPackageInfo(context.getPackageName(),
                    PackageManager.GET_ACTIVITIES).activities[0].name;
            Intent activityIntent = Intent.makeMainActivity(new ComponentName(context, activityClass));
            activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activityIntent.putExtra(PAYLOAD_LABEL, "dummy");
            context.startActivity(activityIntent);
        } catch (Exception e) {
            Log.e(LOG_TAG, "Failed to make startActivity intent: " + e);
        }
    }
}

From source file:br.org.funcate.dynamicforms.markers.MarkersUtilities.java

/**
 * Check if the app is installed.//from  w  w w.j a  va  2  s. c  o  m
 *
 * @param context the context to use.
 * @return <code>true</code> if the app is installed.
 */
public static boolean appInstalled(final Context context) {
    if (MARKERS_IS_INTEGRATED) {
        return true;
    }
    if (!hasApp) {
        List<PackageInfo> installedPackages = new ArrayList<PackageInfo>();
        { // try to get the installed packages list. Seems to have troubles over different
          // versions, so trying them all
            try {
                installedPackages = context.getPackageManager().getInstalledPackages(0);
            } catch (Exception e) {
                // ignore
            }
            if (installedPackages.size() == 0)
                try {
                    installedPackages = context.getPackageManager()
                            .getInstalledPackages(PackageManager.GET_ACTIVITIES);
                } catch (Exception e) {
                    // ignore
                }
        }

        hasApp = installedPackages.size() <= 0;
    }
    return hasApp;
}

From source file:eu.geopaparazzi.library.markers.MarkersUtilities.java

/**
 * Check if the app is installed.//w  w w .  j ava  2 s .c  o m
 *
 * @param context the context to use.
 * @return <code>true</code> if the app is installed.
 */
public static boolean appInstalled(final Context context) {
    if (MARKERS_IS_INTEGRATED) {
        return true;
    }
    if (!hasApp) {
        List<PackageInfo> installedPackages = new ArrayList<PackageInfo>();
        { // try to get the installed packages list. Seems to have troubles over different
          // versions, so trying them all
            try {
                installedPackages = context.getPackageManager().getInstalledPackages(0);
            } catch (Exception e) {
                // ignore
            }
            if (installedPackages.size() == 0)
                try {
                    installedPackages = context.getPackageManager()
                            .getInstalledPackages(PackageManager.GET_ACTIVITIES);
                } catch (Exception e) {
                    // ignore
                }
        }

        if (installedPackages.size() > 0) {
            // if a list is available, check if the status gps is installed
            for (PackageInfo packageInfo : installedPackages) {
                String packageName = packageInfo.packageName;
                if (LOG_HOW)
                    GPLog.addLogEntry("MARKERSUTILITIES", packageName);
                if (packageName.startsWith(APP_PACKAGE)) {
                    hasApp = true;
                    if (LOG_HOW)
                        GPLog.addLogEntry("MARKERSUTILITIES", "Found package: " + packageName);
                    break;
                }
            }
        } else {
            /*
             * if no package list is available, for now try to fire it up anyways.
             * This has been a problem for a user on droidx with android 2.2.1.
             */
            hasApp = true;
        }
    }
    return hasApp;
}

From source file:com.blork.anpod.activity.HomeActivity.java

@Override
protected void onResume() {
    super.onResume();

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);

    try {/*from ww  w .  ja  va2  s  .  c o  m*/
        PackageManager pm = getPackageManager();
        pm.getPackageInfo("com.blork.anpodpro", PackageManager.GET_ACTIVITIES);

        boolean pro = settings.getBoolean("pro", false);
        if (!pro) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Thank you!");
            builder.setMessage("Thanks for buying the donate version - I really appreciate it!")
                    .setCancelable(false)
                    .setNeutralButton("No Problem!", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                            startActivity(new Intent(HomeActivity.this, HomeActivity.class));
                            finish();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        }
        SharedPreferences.Editor pEditor = settings.edit();
        pEditor.putBoolean("pro", true);
        pEditor.commit();
    } catch (NameNotFoundException e1) {
        SharedPreferences.Editor pEditor = settings.edit();
        pEditor.putBoolean("pro", false);
        pEditor.commit();
    }
}

From source file:jahirfiquitiva.iconshowcase.utilities.utils.Utils.java

public static boolean isAppInstalled(Context context, String packageName) {
    final PackageManager pm = context.getPackageManager();
    boolean installed;
    try {/*from   w  w  w .j  a  va  2  s.  co  m*/
        pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        installed = false;
    }
    return installed;
}

From source file:at.tugraz.iaik.magnum.conf.Preferences.java

private List<PackageConfig> listInstalledPackages() {
    List<PackageInfo> packages = ctx.getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
    List<PackageConfig> pkgNames = new LinkedList<PackageConfig>();
    for (PackageInfo info : packages) {
        pkgNames.add(new PackageConfig(info.packageName,
                (String) ctx.getPackageManager().getApplicationLabel(info.applicationInfo)));
        Log.d("PKGNAME", info.packageName);
    }/*  w w  w.  j a  v a 2 s  .c om*/
    return pkgNames;
}