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:Main.java

public static void installApk(Context context, File file) {
    Intent intent = new Intent();
    intent.addFlags(268435456);/*from   w w w  .  ja  v a2  s .c  o  m*/
    intent.setAction("android.intent.action.VIEW");
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    context.startActivity(intent);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.M)
public static List<String> getCustomTabSupportingPackages(Context context) {
    PackageManager pm = context.getPackageManager();
    Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
    // Get all apps that can handle VIEW intents.
    List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, PackageManager.MATCH_ALL);
    List<String> packagesSupportingCustomTabs = new ArrayList<>();
    for (ResolveInfo info : resolvedActivityList) {
        Intent serviceIntent = new Intent();
        serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
        serviceIntent.setPackage(info.activityInfo.packageName);
        if (pm.resolveService(serviceIntent, 0) != null) {
            packagesSupportingCustomTabs.add(info.activityInfo.packageName);
        }/*w ww.j a va2 s.  com*/
    }
    return packagesSupportingCustomTabs;
}

From source file:Main.java

public static void searchMarket(Activity caller, String paramtype, String value) {
    Uri uri = Uri.parse("market://search?q=" + paramtype + ":" + value);
    Intent intent = new Intent();
    intent.setData(uri);//  w  ww.ja v a2 s. c om
    intent.setAction(Intent.ACTION_VIEW);
    caller.startActivity(intent);
}

From source file:Main.java

public static void shareViaIntent(Context context, String subject, String extraText) {
    Intent sendIntent = new Intent();
    sendIntent.setType("text/plain");
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    sendIntent.putExtra(Intent.EXTRA_TEXT, extraText);
    context.startActivity(sendIntent);//from w  w w.ja v a  2  s.c  o  m
}

From source file:Main.java

private static void clearBadgeSony(Context context) {
    String launcherClassName = getLauncherClassName(context);
    if (launcherClassName == null) {
        return;//from  ww  w  . ja  va  2 s.  c o  m
    }

    Intent intent = new Intent();
    intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
    intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", launcherClassName);
    intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);
    intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", String.valueOf(0));
    intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", context.getPackageName());

    context.sendBroadcast(intent);
}

From source file:Main.java

public static void send(Context context, String path) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    PackageManager pm = context.getPackageManager();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType("*/*");
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
    List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    boolean flag = false;
    for (ResolveInfo info : list) {
        if (info.activityInfo.packageName.toLowerCase().contains("bluetooth")
                || info.activityInfo.name.toLowerCase().contains("bluetooth")) {
            ApplicationInfo appInfo = null;
            try {
                appInfo = pm.getApplicationInfo(info.activityInfo.packageName, PackageManager.GET_META_DATA);
            } catch (PackageManager.NameNotFoundException e) {

            }/*from  ww w  .  j  a v  a  2  s  .  c  om*/
            if (appInfo != null && (appInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0
                    && (appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
                flag = true;
                break;
            }
        }
    }
    if (!flag) {
        return;
    }
    context.startActivity(intent);
}

From source file:Main.java

public static void jumpToSystemLocPickImageActivity(Activity activity, int requestCode) {
    Intent intent = null;
    intent = new Intent();
    intent.setType("image/*");
    intent.setAction("android.intent.action.GET_CONTENT");
    activity.startActivityForResult(intent, requestCode);
}

From source file:Main.java

public static void install(Activity activity, File apk_file) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apk_file), "application/vnd.android.package-archive");
    activity.startActivity(intent);/*from w  w  w  . j  a v a2 s. c  om*/
}

From source file:Main.java

private static Intent getApkFileIntent(File file) {
    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");
    return intent;
}

From source file:Main.java

public static Intent getInstallApkIntent(File file) {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
    return intent;
}