Example usage for android.content Intent setClassName

List of usage examples for android.content Intent setClassName

Introduction

In this page you can find the example usage for android.content Intent setClassName.

Prototype

public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className) 

Source Link

Document

Convenience for calling #setComponent with an explicit application package name and class name.

Usage

From source file:com.brewcrewfoo.performance.activities.PCSettings.java

public static boolean isDownloadManagerAvailable(Context context) {
    try {/*from  w  w w  .  j ava  2  s .  c o m*/
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
            return false;
        }
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setClassName("com.android.providers.downloads.ui",
                "com.android.providers.downloads.ui.DownloadList");
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static Intent getApplicationDetailsIntent(String packageName) {

    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;

    if (apiLevel >= 9) { // above 2.3
        intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
        intent.setData(uri);/*from   ww w .j  a v  a  2  s  . c om*/
    } else { // below 2.3
        final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22 : APP_PKG_NAME_21);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName(APP_DETAILS_PACKAGE_NAME, APP_DETAILS_CLASS_NAME);
        intent.putExtra(appPkgName, packageName);
    }
    return intent;
}

From source file:Main.java

public static Intent getLaunchIntent(Context context, String title, String url, String sel) {
    Intent intent = null;
    String number = parseTelephoneNumber(sel);
    if (number != null) {
        intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + number));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    } else {/*from w  ww .  jav  a 2 s . c  o  m*/
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (isMapsURL(url)) {
            intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME);
        } else if (isYouTubeURL(url)) {
            intent.setPackage(YT_PACKAGE_NAME);
        }

        // Fall back if we can't resolve intent (i.e. app missing)
        PackageManager pm = context.getPackageManager();
        if (null == intent.resolveActivity(pm)) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    }

    if (sel != null && sel.length() > 0) {
        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        cm.setText(sel);
    }

    return intent;
}

From source file:com.asksven.betterbatterystats.PackageFragmentActivity.java

public static void showAppOps(Context context, String packageName) {

    Intent intent = null;
    // JB/*www . j  a v a  2s  .  co m*/
    if (Build.VERSION.SDK_INT == 18) {
        intent = new Intent("android.settings.APP_OPS_SETTINGS");
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
    } else if (Build.VERSION.SDK_INT >= 19) {
        // @see http://brightechno.com/blog/archives/211
        intent = new Intent();
        intent.setClassName("com.android.settings", "com.android.settings.Settings");
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.putExtra(":android:show_fragment", "com.android.settings.applications.AppOpsSummary");
    }

    if (intent != null) {
        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(context, context.getString(R.string.message_no_appops), Toast.LENGTH_SHORT).show();
        }

    }
}

From source file:org.restcomm.app.qoslib.Utils.QosAPI.java

public static void checkHostApp(Context context) {
    watchActivity = PreferenceKeys.getSecurePreferences(context).getString("PREF_WATCH_ACTIVITY",
            watchActivity);//from w w w.  j  a  va 2s  .  c om
    if (watchActivity != null) {
        if (System.currentTimeMillis() - lastWatchActivity < 60000 || SystemClock.elapsedRealtime() > 300000)
            return;
        lastWatchActivity = System.currentTimeMillis();
        //int app = Global.getAppImportance (context.getPackageName(), context);
        boolean isRunning = isRunning(context, context.getPackageName());
        // 1 indicates foreground app and 2 indicates background (but not service-only)
        if (isRunning)
            return;
        try {
            // otherwise, launch the apps main activity
            Intent intent = new Intent();
            intent.setClassName(context, watchActivity);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
            LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "checkHostApp mode=", "start " + watchActivity);
        } catch (Exception e) {
            LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "checkHostApp", "exception", e);
        }
    }
}

From source file:com.skubit.comics.activities.ComicViewerActivity.java

public static Intent newInstance(String title, String archiveFile, ArchiveType archiveType, int lastPageRead) {
    if (ArchiveType.ELCX.equals(archiveType)) {
        return ElectricViewerActivity
                .newInstance(new File(Constants.SKUBIT_UNARCHIVES, new File(archiveFile).getName()));
    }/*  ww w  .  jav a2  s .c om*/

    Intent i = new Intent();
    i.putExtra("title", title);
    i.putExtra(ARCHIVE_EXTRA, archiveFile);
    i.putExtra(CURRENT_COMIC_EXTRA, lastPageRead);
    i.putExtra(ARCHIVE_TYPE_EXTRA, archiveType.name());
    i.setClassName(BuildConfig.APPLICATION_ID, ComicViewerActivity.class.getName());
    return i;
}

From source file:Main.java

public static void shareOnTwitter(Context pContext, String urlToShare) {

    Intent tweetIntent = new Intent(Intent.ACTION_SEND);
    tweetIntent.putExtra(Intent.EXTRA_TEXT, urlToShare);
    tweetIntent.setType("text/plain");

    PackageManager packManager = pContext.getPackageManager();
    List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent,
            PackageManager.MATCH_DEFAULT_ONLY);

    boolean resolved = false;
    for (ResolveInfo resolveInfo : resolvedInfoList) {
        if (resolveInfo.activityInfo.packageName.startsWith("com.twitter.android")) {
            tweetIntent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
            resolved = true;//w  w w  . j a v a  2s . c  o m
            break;
        }
    }
    if (resolved) {
        pContext.startActivity(tweetIntent);
    } else {
        Intent i = new Intent();
        i.putExtra(Intent.EXTRA_TEXT, urlToShare);
        i.setAction(Intent.ACTION_VIEW);
        i.setData(Uri.parse("https://twitter.com/intent/tweet?text=message&via=profileName"));
        pContext.startActivity(i);
    }
}

From source file:com.asksven.betterbatterystats.PackageFragmentActivity.java

public static void showInstalledAppDetails(Context context, String packageName) {
    Intent intent = new Intent();
    final int apiLevel = Build.VERSION.SDK_INT;
    if (apiLevel >= 9) {
        // above 2.3
        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        Uri uri = Uri.fromParts(SCHEME, packageName, null);
        intent.setData(uri);/*from  ww  w . j  av a2 s.  com*/
    } else {
        // below 2.3
        final String appPkgName = (apiLevel == 8 ? APP_PKG_NAME_22 : APP_PKG_NAME_21);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setClassName(APP_DETAILS_PACKAGE_NAME, APP_DETAILS_CLASS_NAME);
        intent.putExtra(appPkgName, packageName);
    }
    context.startActivity(intent);
}

From source file:net.vivekiyer.GAL.CorporateAddressBook.java

/**
 * Launches the preferences activity// w ww  .java  2  s .  c  om
 */
public static void showConfiguration(Activity parentActivity) {
    final Intent myIntent = new Intent();
    myIntent.setClassName("net.vivekiyer.GAL", //$NON-NLS-1$
            "net.vivekiyer.GAL.Configure"); //$NON-NLS-1$
    parentActivity.startActivityForResult(myIntent, DISPLAY_CONFIGURATION_REQUEST);
}

From source file:com.readystatesoftware.notificationlog.Log.java

private static boolean isActivityAvailable(Context context, String className) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent();
    final String packageName = context.getApplicationInfo().packageName;
    intent.setClassName(packageName, className);
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}