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:enterprayz.megatools.Tools.java

public static void openBrowser(Activity activity, String url) throws ActivityNotFoundException {
    if (TextUtils.isEmpty(url)) {
        return;// ww  w  . j a v a 2s  . c o  m
    }
    if (!url.startsWith("http://") && !url.startsWith("https://"))
        url = "http://" + url;
    Intent browserIntent;
    if (url.contains("facebook")) {
        browserIntent = newFacebookIntent(activity.getPackageManager(), url);
    } else {
        browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    }
    activity.startActivity(browserIntent);

}

From source file:de.Maxr1998.xposed.maxlock.ui.LockActivity.java

@SuppressLint("WorldReadableFiles")
public static void directUnlock(Activity caller, Intent orig, String pkgName) {
    try {/*from ww  w.  ja  v  a  2  s. c o  m*/
        //noinspection deprecation
        caller.getSharedPreferences(Common.PREFS_PACKAGES, MODE_WORLD_READABLE).edit()
                .putLong(pkgName + "_tmp", System.currentTimeMillis()).commit();
        orig.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION
                | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        caller.startActivity(orig);
    } catch (Exception e) {
        Intent intent_option = caller.getPackageManager().getLaunchIntentForPackage(pkgName);
        intent_option.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION
                | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        caller.startActivity(intent_option);
    } finally {
        caller.finish();
    }
}

From source file:com.forrestguice.suntimeswidget.AlarmDialog.java

/**
 * @param context a context used to start the "show alarm" intent
 *//*  ww w.  j  av  a2s .  c  om*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void showAlarms(Activity context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Intent alarmsIntent = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
        alarmsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        if (alarmsIntent.resolveActivity(context.getPackageManager()) != null) {
            context.startActivity(alarmsIntent);
        }
    }
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openAbout(final Activity activity) {
    try {//from w  ww  .ja v  a2 s  .c o m
        PackageInfo pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        new MaterialDialog.Builder(activity).title(R.string.app_name).theme(Theme.DARK)
                .content(activity.getString(R.string.about_app_description, pInfo.versionName))
                .positiveText(R.string.website).negativeText(R.string.help)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);
                        String url = activity.getString(R.string.website_url);
                        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
                        CustomTabsIntent customTabsIntent = builder.build();
                        try {
                            customTabsIntent.launchUrl(activity, Uri.parse(url));
                        } catch (Exception e) {
                            // There is no way to view the website.
                            activity.startActivity(new Intent(activity, HomepageWebViewActivity.class));
                        }
                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        super.onNegative(dialog);
                        ActivityUtils.openIntroVoluntarily(activity);
                    }
                }).show();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.felkertech.n.ActivityUtils.java

public static void browsePlugins(final Activity activity) {
    //Same opening
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }// w  ww .j  a v  a2  s .c om
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);

    new MaterialDialog.Builder(activity).title(R.string.installed_plugins).items(plugin_names2)
            .itemsCallback(new MaterialDialog.ListCallback() {
                @Override
                public void onSelection(MaterialDialog materialDialog, View view, int i,
                        CharSequence charSequence) {
                    // Load the given plugin with some additional info
                    ChannelDatabase cd = ChannelDatabase.getInstance(activity);
                    String s = cd.toString();
                    Intent intent = new Intent();
                    if (DEBUG) {
                        Log.d(TAG, "Try to start");
                    }
                    ResolveInfo plugin_info = plugins.get(i);
                    Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                            + plugin_info.activityInfo.name);

                    intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                            plugin_info.activityInfo.name);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EXTRA_READ_ALL);
                    intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ALL_CHANNELS, s);
                    activity.startActivity(intent);
                }
            }).positiveText(R.string.download_more_plugins)
            .onPositive(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse("http://play.google.com/store/search?q=cumulustv&c=apps"));
                    activity.startActivity(i);
                }
            }).show();
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openPluginPicker(final boolean newChannel, final JsonChannel queriedChannel,
        final Activity activity) {
    final PackageManager pm = activity.getPackageManager();
    final Intent plugin_addchannel = new Intent(CumulusTvPlugin.ACTION_ADD_CHANNEL);
    final List<ResolveInfo> plugins = pm.queryIntentActivities(plugin_addchannel, 0);
    ArrayList<String> plugin_names = new ArrayList<String>();
    for (ResolveInfo ri : plugins) {
        plugin_names.add(ri.loadLabel(pm).toString());
    }/* w  w w .  ja  va2s . c om*/
    String[] plugin_names2 = plugin_names.toArray(new String[plugin_names.size()]);
    if (DEBUG) {
        Log.d(TAG, "Load plugins " + plugin_names.toString());
    }
    if (plugin_names.size() == 1) {
        Intent intent = new Intent();
        if (newChannel) {
            if (DEBUG) {
                Log.d(TAG, "Try to start ");
            }
            ResolveInfo plugin_info = plugins.get(0);
            if (DEBUG) {
                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                        + plugin_info.activityInfo.name);
            }

            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
        } else {
            ResolveInfo plugin_info = plugins.get(0);
            Log.d(TAG,
                    plugin_info.activityInfo.applicationInfo.packageName + " " + plugin_info.activityInfo.name);
            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                    plugin_info.activityInfo.name);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
        }
        activity.startActivity(intent);
    } else {
        new MaterialDialog.Builder(activity).items(plugin_names2).title(R.string.choose_an_app)
                .content(R.string.choose_default_app).itemsCallback(new MaterialDialog.ListCallback() {
                    @Override
                    public void onSelection(MaterialDialog materialDialog, View view, int i,
                            CharSequence charSequence) {
                        Intent intent = new Intent();
                        if (newChannel) {
                            if (DEBUG) {
                                Log.d(TAG, "Try to start");
                            }
                            ResolveInfo plugin_info = plugins.get(i);
                            if (DEBUG) {
                                Log.d(TAG, plugin_info.activityInfo.applicationInfo.packageName + " "
                                        + plugin_info.activityInfo.name);
                            }

                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);

                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_ADD);
                        } else {
                            ResolveInfo plugin_info = plugins.get(i);
                            intent.setClassName(plugin_info.activityInfo.applicationInfo.packageName,
                                    plugin_info.activityInfo.name);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
                            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, queriedChannel.toString());
                        }
                        activity.startActivity(intent);
                    }
                }).show();
    }
}

From source file:org.noise_planet.noisecapture.MainActivity.java

/**
 * @return Version information on this application
 * @throws PackageManager.NameNotFoundException
 *///from   ww w.j a  v  a  2 s  .c  o m
public static String getVersionString(Activity activity) throws PackageManager.NameNotFoundException {
    String versionName = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
    Date buildDate = new Date(BuildConfig.TIMESTAMP);
    String gitHash = BuildConfig.GITHASH;
    if (gitHash == null || gitHash.isEmpty()) {
        gitHash = "";
    } else {
        gitHash = gitHash.substring(0, 7);
    }
    return activity.getString(R.string.title_appversion, versionName,
            DateFormat.getDateInstance().format(buildDate), gitHash);
}

From source file:org.wahtod.wififixer.utility.LogUtil.java

public static void sendIssueReport(Activity activity, String report, File file) {
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType(activity.getString(R.string.log_mimetype));
    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { activity.getString(R.string.email) });
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.subject));
    Uri uri = FileProvider.getUriForFile(activity, "org.wahtod.wififixer.files", file);
    sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
    List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(sendIntent,
            PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resInfoList) {
        String packageName = resolveInfo.activityInfo.packageName;
        activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }/*from w ww  .j a  v  a2 s  . c  o  m*/
    sendIntent.putExtra(Intent.EXTRA_TEXT, LogUtil.getBuildInfo() + "\n\n" + report);
    activity.startActivityForResult(Intent.createChooser(sendIntent, activity.getString(R.string.emailintent)),
            1);
}

From source file:it.mb.whatshare.Dialogs.java

private static String getBuildDate(final Activity activity) {
    String buildDate = "";
    ZipFile zf = null;//from   w  ww.ja  v a2 s .  com
    try {
        ApplicationInfo ai = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), 0);
        zf = new ZipFile(ai.sourceDir);
        ZipEntry ze = zf.getEntry("classes.dex");
        long time = ze.getTime();
        buildDate = SimpleDateFormat.getInstance().format(new java.util.Date(time));

    } catch (Exception e) {
    } finally {
        if (zf != null) {
            try {
                zf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return buildDate;
}

From source file:com.upnext.blekit.BLEKit.java

/**
 * Checks whether Bluetooth LE is available on the device and Bluetooth turned on.
 *
 * If BLE is not supported, then a dialog with appropriate message is shown.
 * If BLE is supported, but Bluetooth is not turned on then a dialog with message is shown and an option to go directly to settings and turn Bluetooth on.
 *
 * A good place to invoke this method would be onResume() in your Activity.
 *
 * @param activity Activity/*from  ww w  .  j  ava2 s.  c  om*/
 * @return false if BLE is not supported or Bluetooth not turned on; otherwise true
 */
public static boolean checkAvailability(Activity activity) {
    if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        showErrorDialog(activity.getString(R.string.blekit_ble_unsupported), activity, true);
    } else {
        if (((BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter()
                .isEnabled()) {
            return true;
        }
        showErrorDialog(activity.getString(R.string.blekit_bt_not_on), activity, false);
    }
    return false;
}