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 chooserSysPics(Context context, int requestCode) {
    if (context == null) {
        return;//from  ww  w .ja v a 2  s  .  com
    }

    try {
        Intent localIntent = new Intent();
        localIntent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        localIntent.setType("image/*");
        // Intent.ACTION_GET_CONTENT
        localIntent.setAction("android.intent.action.GET_CONTENT");
        if (context instanceof Activity) {
            ((Activity) context).startActivityForResult(localIntent, requestCode);
        } else {
            localIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(localIntent);
        }
    } catch (Exception e) {
    }
}

From source file:org.jnegre.android.osmonthego.service.ExportService.java

public static void startOsmExport(Context context, boolean includeAddress, boolean includeFixme) {
    Intent intent = new Intent(context, ExportService.class);
    intent.setAction(ACTION_EXPORT_OSM);
    intent.putExtra(EXTRA_INCLUDE_ADDRESS, includeAddress);
    intent.putExtra(EXTRA_INCLUDE_FIXME, includeFixme);
    context.startService(intent);/*from   w  w  w  .j  a v a2s.  co m*/
}

From source file:com.digitalbuana.smiles.ui.ContactAdd.java

public static Intent createSubscriptionIntent(Context context, String account, String user) {
    Intent intent = createIntent(context, account, user);
    intent.setAction(ACTION_SUBSCRIPTION_REQUEST);
    return intent;
}

From source file:ch.fixme.status.Widget.java

public static void UpdateAllWidgets(final Context ctxt) {
    AppWidgetManager man = AppWidgetManager.getInstance(ctxt);
    int[] ids = man.getAppWidgetIds(new ComponentName(ctxt, Widget.class));
    Intent ui = new Intent();
    ui.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
    ui.putExtra(Widget.WIDGET_IDS, ids);
    ui.putExtra(Widget.WIDGET_FORCE, true);
    ctxt.sendBroadcast(ui);/*from w  w  w  .  j a  v a 2  s .  c om*/
}

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

/**
 * Constructs an Intent for sharing/sending a file and starts Activity chooser for that Intent
 *
 * @param context Context reference to start the Activity chooser from
 * @param windowTitle the string to be used as the window title for the Activity chooser
 * @param file the File instance to be shared
 * @param mimeType the MIME type for the file to be shared (e.g. image/jpeg)
 * @param messageTitle the message title/subject that may be provided in addition to the file, if supported by the target app
 *//*from  www  .  jav a 2s .co m*/
public static void shareFile(Context context, String windowTitle, File file, final String mimeType,
        String messageTitle) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setType(mimeType);
    intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle);
    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
    context.startActivity(Intent.createChooser(intent, windowTitle));
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.CommandService.java

private static HttpResp<Void> sendCommandWithMedia(final Context ctx, CommandObject cmd)
        throws KurentoCommandException, TransportException, InvalidDataException, NotFoundException {
    String contentPath = cmd.getMedia();

    File content = new File(contentPath);
    String mimeType;//from  w  ww .ja  v a2  s  .  c o  m
    if (content.exists() && content.isFile()) {
        if (contentPath.contains(ConstantKeys.EXTENSION_JPG)) {
            mimeType = ConstantKeys.TYPE_IMAGE;
        } else {
            mimeType = ConstantKeys.TYPE_VIDEO;
        }
    } else {
        String error = contentPath + " does not exists or is not a file";
        log.error(error);
        throw new KurentoCommandException(error);
    }

    CustomMultiPartEntity mpEntity;
    final String json = cmd.getJson();
    String charset = HTTP.UTF_8;
    long contentSize = 0;
    try {
        contentSize = content.length();
        /* Aprox. total size */
        final long totalSize = content.length() + json.getBytes("UTF-16BE").length;
        mpEntity = new CustomMultiPartEntity(new CustomMultiPartEntity.ProgressListener() {

            private int i;

            @Override
            public void transferred(long num) {
                int totalpercent = Math.min(100, (int) ((num * 100) / totalSize));

                if (totalpercent > (1 + PERCENT_INC * i) || totalpercent >= 100) {
                    Intent intent = new Intent();
                    intent.setAction(ConstantKeys.BROADCAST_PROGRESSBAR);
                    intent.putExtra(ConstantKeys.JSON, json);
                    intent.putExtra(ConstantKeys.TOTAL, totalpercent);
                    ctx.sendBroadcast(intent);
                    i++;
                }
            }
        });

        mpEntity.addPart(COMMAND_PART_NAME,
                new StringBody(json, HttpManager.CONTENT_TYPE_APPLICATION_JSON, Charset.forName(charset)));

        FormBodyPart fbp = new FormBodyPart(CONTENT_PART_NAME, new FileBody(content, mimeType));
        fbp.addField(HTTP.CONTENT_LEN, String.valueOf(contentSize));
        mpEntity.addPart(fbp);

    } catch (UnsupportedEncodingException e) {
        String msg = "Cannot use " + charset + "as entity";
        log.error(msg, e);
        throw new TransportException(msg);
    }

    return HttpManager.sendPostVoid(ctx, ctx.getString(R.string.url_command), mpEntity);
}

From source file:com.theelix.libreexplorer.FileManager.java

/**
 * This method chooses the appropriate Apps and Open the file
 *
 * @param file The target file/*ww w.j  av a2 s. c o  m*/
 */
public static void openFile(File file) {
    try {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(file);
        String mimeType = FileUtilties.getMimeType(uri);
        if (mimeType == null) {
            mimeType = "*/*";
        }
        intent.setDataAndType(uri, mimeType);
        mContext.startActivity(Intent.createChooser(intent, null));
    } catch (ActivityNotFoundException e) {
        //Activity is not found so App'll start an intent with generic Mimetype
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(file);
        intent.setDataAndType(uri, "*/*");
        mContext.startActivity(Intent.createChooser(intent, null));
    }

}

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

public static boolean isSamsungBrowserAvailable(Context context) {
    Intent intent = new Intent();
    intent.setAction(SAMSUNG_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(SAMSUNG_PACKAGE_PREFIX)
                    || info.activityInfo.packageName.contains(SAMSUNG)) {
                return true;
            }//w ww .  j a v a 2s. c  om
        }
    }
    return false;
}

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

public static Set<String> getBrowsersAvailableByIntent(Context context) {
    Set<String> result = new HashSet<>();
    Intent intent = new Intent();
    intent.setAction(SAMSUNG_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(YANDEX)) {
                result.add(YANDEX);/*from   w ww.java  2  s  .  co m*/
            } else if (info.activityInfo.packageName.contains(SAMSUNG_PACKAGE_PREFIX)
                    || info.activityInfo.packageName.contains(SAMSUNG)) {
                result.add(SAMSUNG);
            }
        }
    }

    return result;
}

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

public static void openSamsungBlockingOptions(Context context) {
    Intent intent = new Intent();
    intent.setAction(SAMSUNG_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) {
        boolean found = false;
        for (ResolveInfo info : list) {
            if (info.activityInfo.packageName.contains(SAMSUNG_PACKAGE_PREFIX)
                    || info.activityInfo.packageName.contains(SAMSUNG)) {
                found = true;//  w w w.  j  a  v a2s  . c o  m
                intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
            }
        }
        if (found) {
            context.startActivity(intent);
        }
    }
}