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:fr.inria.ucn.Helpers.java

/**
 * Request data collection sample.//from   w  ww  .  jav  a2  s .  c  om
 *  
 * @param context
 * @param wl         Need wakelock?
 */
public static void doSample(Context context, boolean wl) {
    if (wl)
        Helpers.acquireLock(context);
    Intent sintent = new Intent(context, CollectorService.class);
    sintent.setAction(Constants.ACTION_COLLECT);
    if (wl)
        sintent.putExtra(Constants.INTENT_EXTRA_RELEASE_WL, true); // request service to release the wl
    context.startService(sintent);
}

From source file:fr.inria.ucn.Helpers.java

/**
 * Request data upload./* w  ww . j av  a2s. c o m*/
 *  
 * @param context
 * @param wl         Need wakelock?
 */
public static void doUpload(Context context, boolean wl) {
    if (wl)
        Helpers.acquireLock(context);
    Intent sintent = new Intent(context, CollectorService.class);
    sintent.setAction(Constants.ACTION_UPLOAD);
    if (wl)
        sintent.putExtra(Constants.INTENT_EXTRA_RELEASE_WL, true); // request service to release the wl
    context.startService(sintent);
}

From source file:fr.inria.ucn.Helpers.java

/**
 * Start (schedule) the data collector service.
 *  //from w  w w .j ava  2s  . c o m
 * @param context
 * @param wl         Need wakelock?
 */
public static void startCollector(Context context, boolean wl) {
    if (wl)
        Helpers.acquireLock(context);
    Intent sintent = new Intent(context, CollectorService.class);
    sintent.setAction(Constants.ACTION_SCHEDULE);
    sintent.putExtra(Constants.INTENT_EXTRA_SCHEDULER_START, true);
    if (wl)
        sintent.putExtra(Constants.INTENT_EXTRA_RELEASE_WL, true); // request service to release the wl
    context.startService(sintent);
}

From source file:fr.inria.ucn.Helpers.java

/**
 * Stop (schedule) the data collector service.
 *  //from   ww w.ja va  2 s. com
 * @param context
 * @param wl         Need wakelock?
 */
public static void stopCollector(Context context, boolean wl) {
    if (wl)
        Helpers.acquireLock(context);
    Intent sintent = new Intent(context, CollectorService.class);
    sintent.setAction(Constants.ACTION_SCHEDULE);
    sintent.putExtra(Constants.INTENT_EXTRA_SCHEDULER_START, false);
    if (wl)
        sintent.putExtra(Constants.INTENT_EXTRA_RELEASE_WL, true); // request service to release the wl
    context.startService(sintent);
}

From source file:fr.inria.ucn.Helpers.java

/**
 * Collectors and Listeners should use this method to send the results to the service.
 * @param c/*from ww  w  . j a v  a2s .c o m*/
 * @param cid data collection id (maps to mongodb collection used to store the data)
 * @param ts  periodic collection timestamp or event time if triggered by timestamp
 * @param data 
 */
@SuppressLint("SimpleDateFormat")
public static void sendResultObj(Context c, String cid, long ts, JSONObject data) {
    try {

        // wrap the collected data object to a common object format
        JSONObject res = new JSONObject();

        // data collection in the backend db
        res.put("collection", cid);

        // store unique user id to each result object
        res.put("uid", getDeviceUuid(c));

        // app version to help to detect data format changes
        try {
            PackageManager manager = c.getPackageManager();
            PackageInfo info = manager.getPackageInfo(c.getPackageName(), 0);
            res.put("app_version_name", info.versionName);
            res.put("app_version_code", info.versionCode);
        } catch (NameNotFoundException e) {
        }

        // event and current time in UTC JSON date format
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        res.put("ts_event", sdf.format(new Date(ts)));
        res.put("ts", sdf.format(new Date()));
        res.put("tz", TimeZone.getDefault().getID()); // devices current timezone
        res.put("tz_offset", TimeZone.getDefault().getOffset(ts)); // ts offset to this event

        // the data obj
        res.put("data", data);

        // ask the service to handle the data
        Intent intent = new Intent(c, CollectorService.class);
        intent.setAction(Constants.ACTION_DATA);
        intent.putExtra(Constants.INTENT_EXTRA_DATA, res.toString());
        c.startService(intent);

        Log.d(Constants.LOGTAG, res.toString(4));

    } catch (JSONException ex) {
        Log.w(Constants.LOGTAG, "failed to create json obj", ex);
    }
}

From source file:com.game.simple.Game3.java

public static void openImage() {
    //---timer---//
    //StartReConnect();
    //-----------//
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.putExtra("return-data", true);
    self.startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}

From source file:com.felkertech.n.ActivityUtils.java

public static void writeDriveData(final Activity context, GoogleApiClient gapi) {
    //Ask here for permission to storage
    PermissionUtils.requestPermissionIfDisabled(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
            context.getString(R.string.permission_storage_rationale));
    if (PermissionUtils.isDisabled(context, android.Manifest.permission_group.STORAGE)) {
        new MaterialDialog.Builder(context).title(R.string.permission_not_allowed_error)
                .content(R.string.permission_not_allowed_text).positiveText(R.string.permission_action_settings)
                .negativeText(R.string.ok).callback(new MaterialDialog.ButtonCallback() {
                    @Override//from  w  ww  . j  a v a2 s . co m
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);
                        Intent intent = new Intent();
                        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        Uri uri = Uri.fromParts("package", context.getPackageName(), null);
                        intent.setData(uri);
                    }
                }).build();
    } else
        actuallyWriteData(context, gapi);
}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

private static boolean installShortcut(Context context, Intent data, ArrayList<ItemInfo> items, String name,
        final Intent intent, final int screen, boolean shortcutExists, final SharedPreferences sharedPrefs,
        int[] result) {
    int[] tmpCoordinates = new int[2];
    if (findEmptyCell(context, items, tmpCoordinates, screen)) {
        if (intent != null) {
            if (intent.getAction() == null) {
                intent.setAction(Intent.ACTION_VIEW);
            } else if (intent.getAction().equals(Intent.ACTION_MAIN) && intent.getCategories() != null
                    && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            }/*from w ww.  ja  v  a 2s  .  com*/

            // By default, we allow for duplicate entries (located in
            // different places)
            boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
            if (duplicate || !shortcutExists) {
                new Thread("setNewAppsThread") {
                    public void run() {
                        synchronized (sLock) {
                            // If the new app is going to fall into the same page as before,
                            // then just continue adding to the current page
                            final int newAppsScreen = sharedPrefs.getInt(NEW_APPS_PAGE_KEY, screen);
                            SharedPreferences.Editor editor = sharedPrefs.edit();
                            if (newAppsScreen == -1 || newAppsScreen == screen) {
                                addToStringSet(sharedPrefs, editor, NEW_APPS_LIST_KEY, intent.toUri(0));
                            }
                            editor.putInt(NEW_APPS_PAGE_KEY, screen);
                            editor.commit();
                        }
                    }
                }.start();

                // Update the Launcher db
                LauncherApplication app = (LauncherApplication) context.getApplicationContext();
                ShortcutInfo info = app.getModel().addShortcut(context, data,
                        LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, tmpCoordinates[0],
                        tmpCoordinates[1], true);
                if (info == null) {
                    return false;
                }
            } else {
                result[0] = INSTALL_SHORTCUT_IS_DUPLICATE;
            }

            return true;
        }
    } else {
        result[0] = INSTALL_SHORTCUT_NO_SPACE;
    }

    return false;
}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

public static void createShortcut(Activity main, String path) {
    File file = new File(path);

    try {/*www  . j  a  va2 s .  co  m*/
        // Create the intent that will handle the shortcut
        Intent shortcutIntent = new Intent(main, Browser.class);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        shortcutIntent.putExtra(Browser.EXTRA_SHORTCUT, path);

        // The intent to send to broadcast for register the shortcut intent
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, file.getName());
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(main, R.drawable.ic_launcher));
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        main.sendBroadcast(intent);

        Toast.makeText(main, main.getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(main, main.getString(R.string.error), Toast.LENGTH_SHORT).show();
    }
}

From source file:com.fvd.nimbus.MainActivity.java

public static void createShortcut(Context context) {

    Intent shortcutIntent = new Intent(context, MainActivity.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Nimbus Clipper");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.app_icon));
    addIntent.putExtra("duplicate", false);
    addIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);//from w ww.ja  v a2s .  c o  m
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
}