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.danielhalupka.imageviewer.ImageViewer.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {//w  w w . ja  v  a2 s  .  c  om
        if (ACTION_VIEW_IMAGE.equals(action)) {
            JSONObject arg_object = args.getJSONObject(0);
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            String filePath = arg_object.getString("filepath");
            intent.setDataAndType(Uri.parse(filePath), "image/*");
            this.cordova.getActivity().startActivity(intent);
            callbackContext.success();
            return true;
        }
        callbackContext.error("Invalid action");
        return false;
    } catch (JSONException e) {
        System.err.println("Exception: " + e.getMessage());
        callbackContext.error(e.getMessage());
        return false;
    }
}

From source file:com.manning.androidhacks.hack039.MainActivity.java

public void onLayarClick(View v) {
    if (!ActivityHelper.isLayarAvailable(this)) {
        ActivityHelper.showDownloadDialog(this);
    } else {/*  w w  w.  jav  a  2s  .com*/
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        Uri uri = Uri.parse("layar://teather/?action=refresh");
        intent.setData(uri);
        startActivity(intent);
    }

}

From source file:com.manning.androidhacks.hack046.MainActivity.java

public void onReceiveMsgClick(View v) {
    Intent intent = new Intent(this, MsgService.class);
    intent.setAction(MsgService.MSG_RECEIVE);
    startService(intent);/*from w  w  w  . jav  a 2  s  . c  om*/
}

From source file:info.zamojski.soft.towercollector.broadcast.ExternalBroadcastSender.java

private void sendMeasurementsCollectedBroadcast(List<Measurement> measurements) {
    Log.i("sendMeasurementsCollectedBroadcast(): Sending broadcast to external apps");
    if (formatter == null) {
        formatter = new JsonBroadcastFormatter();
    }// w  ww  .jav  a 2 s . co  m
    try {
        String extra = formatter.formatList(measurements);
        // Send broadcast
        Intent intent = new Intent();
        intent.setAction(measurementsCollectedAction);
        intent.putExtra(measurementsExtraKey, extra);
        MyApplication.getApplication().sendBroadcast(intent);
        Log.d("sendMeasurementsCollectedBroadcast(): Broadcasted " + extra);
    } catch (JSONException ex) {
        Log.e("sendMeasurementsCollectedBroadcast(): Failed to serialize list of measurements to JSON", ex);
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.IMObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.setComponent(new ComponentName(context.getPackageName(), HomeActivity.class.getName()));
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);
    String msg = obj.optString(TEXT);
    (new PresenceAwareNotify(context)).notify("IM from " + from.name, "IM from " + from.name, "\"" + msg + "\"",
            contentIntent);/*from   www  .  j  a  v a  2  s .  c  om*/
}

From source file:com.nadmm.airports.tfr.TfrServiceBase.java

protected Intent makeResultIntent(String action) {
    Intent intent = new Intent();
    intent.setAction(action);
    return intent;
}

From source file:com.manning.androidhacks.hack046.MsgActivity.java

public void onDeleteClick(View v) {
    Intent intent = new Intent(this, MsgService.class);
    intent.setAction(MsgService.MSG_DELETE);
    startService(intent);//from  w  w  w . j  a v a  2  s.  c om
    finish();
}

From source file:MainActivity.java

public void cancelAlarm() {
    Intent intentToFire = new Intent(getApplicationContext(), AlarmBroadcastReceiver.class);
    intentToFire.setAction(AlarmBroadcastReceiver.ACTION_ALARM);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intentToFire, 0);
    AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(alarmIntent);/*from   w w w.j  ava2  s  . c  o m*/
}

From source file:MainActivity.java

public void setAlarm(View view) {
    Intent intentToFire = new Intent(getApplicationContext(), AlarmBroadcastReceiver.class);
    intentToFire.setAction(AlarmBroadcastReceiver.ACTION_ALARM);
    PendingIntent alarmIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intentToFire, 0);
    AlarmManager alarmManager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    long thirtyMinutes = SystemClock.elapsedRealtime() + 30 * 1000;
    alarmManager.set(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, alarmIntent);

    //alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, thirtyMinutes, AlarmManager.INTERVAL_HALF_HOUR, alarmIntent);
}

From source file:com.phonegap.plugins.openfilewithexternalapp.OpenFileWithExternalApp.java

public PluginResult execute(String action, JSONArray args, String callbackId) {

    try {//from  w w  w .j  a  v  a  2 s . c om

        String filePath = args.getString(0);

        Intent intent = new Intent();

        intent.setAction(android.content.Intent.ACTION_VIEW);

        File fileToOpen = new File(filePath);

        MimeTypeMap mime = MimeTypeMap.getSingleton();

        String extension = fileToOpen.getName().substring(fileToOpen.getName().lastIndexOf(".") + 1)
                .toLowerCase();

        String type = mime.getMimeTypeFromExtension(extension);

        intent.setAction(Intent.ACTION_VIEW);

        Uri uri = Uri.fromFile(fileToOpen);

        intent.setDataAndType(uri, type);

        this.ctx.startActivity(intent);
    }

    catch (JSONException e) {

        e.printStackTrace();

    }

    PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);

    return mPlugin;
}