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 sendBroadcast(Context context, String filter) {
    if (context == null) {
        return;//from  ww w .j a v a  2s  . co m
    }
    Intent intent = new Intent();
    intent.setAction(filter);
    context.sendBroadcast(intent);
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, Bundle bundle) {
    if (context == null) {
        return;//  w  w  w  .  j a  va 2s.  com
    }
    Intent intent = new Intent();
    intent.setAction(filter);
    intent.putExtras(bundle);
    context.sendBroadcast(intent);
}

From source file:Main.java

public static void sendBroadcast(Context context, String filter, String bundleName, Bundle bundle) {
    if (context == null) {
        return;/*  ww  w  . j a v  a 2s.  c  o  m*/
    }
    Intent intent = new Intent();
    intent.setAction(filter);
    intent.putExtra(bundleName, bundle);
    context.sendBroadcast(intent);
}

From source file:Main.java

public static Intent getApkFileIntent(String param) {

    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(new File(param));
    intent.setDataAndType(uri, "application/vnd.android.package-archive");
    return intent;
}

From source file:Main.java

public static void installAPK(Context context, File file) {
    if (file == null || !file.exists())
        return;//w ww . j  a  v a 2s.c o m
    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");
    context.startActivity(intent);
}

From source file:Main.java

public static void installApp(Context context, File apkFile) {
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");

    context.startActivity(intent);/* ww w  . j a  va  2s  .co  m*/
    // YxCfgManager.getYxCfgInstance().write(YxAppCfg.IS_FIRST, true);
}

From source file:com.manning.androidhacks.hack046.helper.NotificationHelper.java

private static PendingIntent getDeletePendingIntent(Context ctx) {
    Intent intent = new Intent(ctx, MsgService.class);
    intent.setAction(MsgService.MSG_DELETE);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return PendingIntent.getService(ctx, 0, intent, 0);
}

From source file:Main.java

/**
 * Save a media in the downloads directory and offer to open it with a third party application.
 * @param activity the activity/*ww w .  ja va  2 s  . co  m*/
 * @param savedMediaPath the media path
 * @param mimeType the media mime type.
 */
public static void openMedia(final Activity activity, final String savedMediaPath, final String mimeType) {
    if ((null != activity) && (null != savedMediaPath)) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    File file = new File(savedMediaPath);
                    Intent intent = new Intent();
                    intent.setAction(android.content.Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.fromFile(file), mimeType);
                    activity.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(activity, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                }
            }
        });
    }
}

From source file:Main.java

public static void jumpToApplicationDetail(Context context) {
    Intent localIntent = new Intent();
    localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
    localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
    context.startActivity(localIntent);/*from  ww w  .  j a v  a  2s.c  om*/
}

From source file:Main.java

/**
 * Returns an intent calling the android chooser. The chooser will provide apps, which listen to one of the following actions
 * {@link Intent#ACTION_GET_CONTENT} , {@link MediaStore#ACTION_IMAGE_CAPTURE}, {@link MediaStore#ACTION_VIDEO_CAPTURE},
 * {@link MediaStore.Audio.Media#RECORD_SOUND_ACTION}
 * /*from  w w w .ja v a  2  s . c  o  m*/
 * @return Intent that opens the app chooser.
 */
public static Intent getChooserIntent() {
    // GET_CONTENT Apps
    Intent getContentIntent = new Intent();
    getContentIntent.setAction(Intent.ACTION_GET_CONTENT);
    getContentIntent.setType("*/*");
    getContentIntent.addCategory(Intent.CATEGORY_OPENABLE);
    // ACTION_IMAGE_CAPTURE Apps
    Intent captureImageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // ACTION_VIDEO_CAPTURE Apps
    Intent captureVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    // RECORD_SOUND_ACTION Apps
    Intent recordSoungIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    Intent finalIntent = Intent.createChooser(getContentIntent, "test");
    finalIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            new Intent[] { captureImageIntent, captureVideoIntent, recordSoungIntent });
    return finalIntent;
}