Example usage for android.content Intent setAction

List of usage examples for android.content Intent setAction

Introduction

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

Prototype

public @NonNull Intent setAction(@Nullable String action) 

Source Link

Document

Set the general action to be performed.

Usage

From source file:com.adguard.android.commons.BrowserUtils.java

private static ComponentName getYandexBrowser(Context context, String action) {
    Intent mainIntent = new Intent();
    mainIntent.setAction(action);

    for (String packageName : yandexBrowserPackageList) {
        mainIntent.setPackage(packageName);

        List<ResolveInfo> installedPackages = context.getPackageManager().queryIntentActivities(mainIntent,
                PackageManager.MATCH_DEFAULT_ONLY);

        if (!installedPackages.isEmpty()) {
            ResolveInfo resolveInfo = installedPackages.get(0);

            return new ComponentName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
        }// w  w  w  .j a v  a 2  s  .c  o  m
    }

    return null;
}

From source file:com.adguard.android.commons.BrowserUtils.java

public static void openYandexBlockingOptions(Context context) {
    Intent intent = new Intent();
    intent.setAction(YANDEX_CONTENT_BLOCKER_ACTION);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        context.startActivity(intent);//w w  w .  j av a  2s  .com
        return;
    }

    // For samsung-type action in Yandex browser
    intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION);
    list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {

        ComponentName componentName = getYandexBrowser(context, SAMSUNG_CONTENT_BLOCKER_ACTION);
        if (componentName != null) {
            intent.setClassName(componentName.getPackageName(), componentName.getClassName());
        }

        context.startActivity(intent);
    }
}

From source file:com.adguard.android.commons.BrowserUtils.java

public static boolean isYandexBrowserAvailable(Context context) {
    Intent intent = new Intent();
    intent.setAction(YANDEX_CONTENT_BLOCKER_ACTION);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        for (ResolveInfo info : list) {
            if (info.activityInfo.packageName.contains(MainActivity.YANDEX)) {
                return true;
            }//from   w ww  .ja v  a2  s.  c o  m
        }
    }

    // For samsung-type action in Yandex browser
    intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION);
    list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        for (ResolveInfo info : list) {
            if (info.activityInfo.packageName.contains(MainActivity.YANDEX)) {
                return true;
            }
        }
    }
    return false;
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * ?Intent??/*  ww w .ja va 2 s  . c o  m*/
 */
public static Intent createSendTextIntent(String text) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, text);
    return intent;
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * ??Intent??//from  w ww  .  j av a 2s. c om
 */
public static Intent createSendImageIntent(String filePath) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setType(MediaUtils.getMimeType(filePath));
    intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath));
    return intent;
}

From source file:im.delight.android.commons.Social.java

/**
 * Displays an application chooser and shares the specified file using the selected application
 *
 * @param context a context reference/*from   w  ww. j  a  v a  2  s.c  om*/
 * @param windowTitle the title for the application chooser's window
 * @param fileToShare the file to be shared
 * @param mimeTypeForFile the MIME type for the file to be shared (e.g. `image/jpeg`)
 * @param subjectTextToShare the message title or subject for the file, if supported by the target application
 */
public static void shareFile(final Context context, final String windowTitle, final File fileToShare,
        final String mimeTypeForFile, final String subjectTextToShare) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType(mimeTypeForFile);
    intent.putExtra(Intent.EXTRA_SUBJECT, subjectTextToShare);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileToShare));
    context.startActivity(Intent.createChooser(intent, windowTitle));
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

private static ShortcutInfo getShortcutInfo(Context context, Intent data, Intent launchIntent) {
    if (launchIntent.getAction() == null) {
        launchIntent.setAction(Intent.ACTION_VIEW);
    } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && launchIntent.getCategories() != null
            && launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    }/*from ww w  .j ava  2  s. c om*/
    LauncherAppState app = LauncherAppState.getInstance();
    return app.getModel().infoFromShortcutIntent(context, data, null);
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * Intent???//  w  w w  .  ja  va 2 s  . c om
 *
 * @param intent
 * @param filePaths
 * @param mimeType
 * @return
 */
public static Intent addFiles(Intent intent, ArrayList<String> filePaths, String mimeType) {
    intent.setAction(Intent.ACTION_SEND_MULTIPLE);
    intent.setType(mimeType);
    ArrayList<Uri> uris = new ArrayList<Uri>(filePaths.size());
    for (String filePath : filePaths) {
        uris.add(Uri.fromFile(new File(filePath)));
    }
    intent.putExtra(Intent.EXTRA_STREAM, uris);
    return intent;
}

From source file:Main.java

public static void installLaunchShortCut(Context context, Intent intent, String shortCutName, Bitmap icon,
        boolean duplicate) {
    Intent shortCutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    shortCutIntent.putExtra("duplicate", duplicate);
    intent.setAction(Intent.ACTION_MAIN);
    shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    context.sendBroadcast(shortCutIntent);
}

From source file:Main.java

/** Google calendar intent variant 1 */
private static Intent constructGoogleCalendarIntentVariant2() {
    final Intent intent = new Intent();

    // Newer calendar have API for launching the google calendar. See documentation at:
    // http://developer.android.com/guide/topics/providers/calendar-provider.html#intents
    final long startTimeMillis = System.currentTimeMillis();
    final String url = "content://com.android.calendar/time/" + startTimeMillis;
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));/*  www .j a  va2  s .  c om*/

    return intent;
}