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:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.services.WebRequestService.java

/**
 * Sends an event to a specific channel using the LocalBroadcastManager
 * @param Event to send/*w  w  w .j  av a 2s  .c  o m*/
 * @param Channel on which the event is sent
 */
protected void sendToChannel(Event evt, String channel) {
    Intent i = new Intent();
    i.putExtra(Event.PARCELABLE_EXTRA_EVENT_TYPE, evt.getEventType());
    i.putExtra(Event.PARCELABLE_EXTRA_EVENT, evt);
    i.setAction(channel);
    LocalBroadcastManager.getInstance(this).sendBroadcast(i);
}

From source file:alaindc.crowdroid.SensorsIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (action.equals(Constants.INTENT_START_SENSORS)) {

            // Init throughput taken
            SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putBoolean(Constants.THROUGHPUT_TAKEN, false);
            editor.commit();/*from  w w w .  j  a v  a2  s .  co m*/

            // Configure sensors and eventlistener
            mSensorManager = (SensorManager) getApplicationContext().getSystemService(Context.SENSOR_SERVICE);
            List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
            for (Sensor sensor : sensorList) {
                if (Constants.isInMonitoredSensors(sensor.getType()))
                    mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
            }

            // TODO STUB: Comment this in release
            for (int type : Constants.STUBBED_MONITORED_SENSORS) {
                stub_onSensorChanged(type);
            }

        }

        if (action.equals(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE)) {
            // Configure amplitude and start TEST
            amplitudeTask = new GetAmplitudeTask(this);
            amplitudeTask.getData();
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_AMBIENT_TEMPERATURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_PRESSURE)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_STUB_SENSOR_CHANGED + Sensor.TYPE_RELATIVE_HUMIDITY)) {
            stub_onSensorChanged(intent.getIntExtra(Constants.INTENT_STUB_SENSOR_CHANGED_TYPE, -1));
        }

        if (action.equals(Constants.INTENT_RECEIVED_AMPLITUDE)) {
            double amplitude = intent.getDoubleExtra(Constants.EXTRA_AMPLITUDE, -1);

            if (amplitude > 0) {
                SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString(Constants.PREF_SENSOR_ + Constants.TYPE_AMPLITUDE, Double.toString(amplitude));
                editor.commit();

                // Update view
                Intent senseintent = new Intent(Constants.INTENT_UPDATE_SENSORS);
                senseintent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA,
                        "Sensor " + Constants.getNameOfSensor(Constants.TYPE_AMPLITUDE) + " value: "
                                + Double.toString(amplitude));
                LocalBroadcastManager.getInstance(this).sendBroadcast(senseintent);
            }

            int index = Constants.getIndexAlarmForSensor(Constants.TYPE_AMPLITUDE);

            // Set the alarms for next sensing of amplitude
            alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
            Intent intentAlarm = new Intent(getApplicationContext(), SensorsIntentService.class);
            intentAlarm.setAction(Constants.INTENT_START_AUDIOAMPLITUDE_SENSE);
            alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0);

            // TIMEOUT for another monitoring of audio
            int seconds = 30; // TODO: De-hardcode this
            alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000,
                    alarmIntent);

        }
    }
}

From source file:com.gelecekonline.android.uploadornek.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    selectedImageView = (ImageView) findViewById(R.id.selectedImageView);
    selectImageButton = (Button) findViewById(R.id.selectImageButton);
    selectImageButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            try {
                //Resim secen Intent tanimlamasi
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, getString(R.string.select_image)),
                        SELECT_IMAGE_INTENT_ID);
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), getString(R.string.select_image_problem),
                        Toast.LENGTH_LONG).show();
            }//from w  ww .j  a v  a2  s  .c om
        }
    });

    uploadButton = (Button) findViewById(R.id.uploadButton);
    uploadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (selectedImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), getString(R.string.please_select_image),
                        Toast.LENGTH_LONG).show();
            } else {
                dialog = ProgressDialog.show(MainActivity.this, getString(R.string.image_uploading),
                        getString(R.string.please_wait), true);
                if (uploadImageTask == null || uploadImageTask.getStatus() == AsyncTask.Status.FINISHED) {
                    uploadImageTask = new UploadImageTask();
                }
                uploadImageTask.execute();
            }
        }
    });
}

From source file:com.bczm.widgetcollections.player.MusicPlayer.java

@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
    LogUtils.e("second percent --> " + percent);
    //        TLog.d(TAG, "second percent --> " + percent);
    if (percent < 100) {
        Intent intent = new Intent();
        intent.setAction(Constants.ACTION_MUSIC_SECOND_PROGRESS_BROADCAST);
        intent.putExtra(Constants.KEY_MUSIC_SECOND_PROGRESS, percent);
        mContext.sendBroadcast(intent);//from w w  w  .j  a v a 2s  . c om
    }
}

From source file:alaindc.crowdroid.SendIntentService.java

private void handleActionReceivedData(String response) {

    // Data got from server response
    int timeout; // sec
    double radius; // meters
    int sensor;/*from   w  ww  . j ava2 s  .  com*/
    double latitude, longitude;

    // Update view sending a broadcast intent
    Intent intent = new Intent(Constants.INTENT_RECEIVED_DATA);
    intent.putExtra(Constants.INTENT_RECEIVED_DATA_EXTRA_DATA, response);
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

    try {
        JSONArray jsonArray = new JSONArray(response);
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        sensor = jsonObject.getInt("sensor");
        // For time homogeneity
        timeout = jsonObject.getInt("timeout");
        // For space homogeneity
        radius = jsonObject.getDouble("radius");
        latitude = jsonObject.getDouble("lat");
        longitude = jsonObject.getDouble("long");

    } catch (JSONException e) {
        return;
    }

    if (sensor == Constants.TYPE_TEL) {
        SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
                Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putBoolean(Constants.THROUGHPUT_TAKEN, false);
        editor.commit();
    }

    Intent geofenceIntent = new Intent(getApplicationContext(), GeofenceIntentService.class);
    geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_SENSORTYPE, sensor);
    geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_LATITUDE, latitude);
    geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_LONGITUDE, longitude);
    geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_RADIUS, String.valueOf(radius));
    geofenceIntent.putExtra(Constants.EXTRA_GEOFENCE_EXPIRE_MILLISEC, String.valueOf(timeout * 1000));
    getApplicationContext().startService(geofenceIntent);

    // Set timeout based on server response
    alarmMgr = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    Intent intentAlarm = new Intent(getApplicationContext(), SendIntentService.class);
    intentAlarm.setAction(Constants.ACTION_SENDDATA + sensor);
    intentAlarm.putExtra(Constants.EXTRA_TYPE_OF_SENSOR_TO_SEND, sensor);
    alarmIntent = PendingIntent.getService(getApplicationContext(), 0, intentAlarm, 0);

    int seconds = timeout;
    alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + seconds * 1000,
            alarmIntent);
}

From source file:com.halseyburgund.rwframework.core.RWStreamAssetsTracker.java

/**
 * Sends a RW.STREAM_METADATA_UPDATED broadcast intent that apps can
 * listen for to be notified about changes in the asset being played.
 * /*from  ww w .  j av  a  2s. c o  m*/
 * @param currentAssetId of asset that started playing
 * @param previousAssetId of asset that finished playing
 * @param meta Title of the asset
 */
private void broadcastStreamMetadataUpdate(int currentAssetId, int previousAssetId, String meta) {
    Intent intent = new Intent();
    intent.setAction(RW.STREAM_METADATA_UPDATED);
    intent.putExtra(RW.EXTRA_STREAM_METADATA_CURRENT_ASSET_ID, currentAssetId);
    intent.putExtra(RW.EXTRA_STREAM_METADATA_PREVIOUS_ASSET_ID, previousAssetId);
    intent.putExtra(RW.EXTRA_STREAM_METADATA_TITLE, meta);
    if (D) {
        Log.d(TAG, "Going to send broadcast event, action = " + intent.getAction(), null);
    }
    mRwService.sendBroadcast(intent);
}

From source file:com.krayzk9s.imgurholo.activities.ImgurHoloActivity.java

public void imageSelected(ArrayList<JSONParcelable> data, int position) {
    FrameLayout displayFrag = (FrameLayout) findViewById(R.id.frame_layout_child);
    if (displayFrag == null) {
        // DisplayFragment (Fragment B) is not in the layout (handset layout),
        // so start DisplayActivity (Activity B)
        // and pass it the info about the selected item
        if (getApiCall().settings.getBoolean("ImagePagerEnabled", false) == false) {
            Intent intent = new Intent();
            intent.putExtra("id", data.get(position));
            Log.d("data", data.get(position).toString());
            intent.setAction(ImgurHoloActivity.IMAGE_INTENT);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(intent);//from w  w  w. j  a  v a 2 s  . co  m
        } else {
            Intent intent = new Intent();
            intent.putExtra("ids", data);
            intent.putExtra("start", position);
            intent.setAction(ImgurHoloActivity.IMAGE_PAGER_INTENT);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            startActivity(intent);
        }
    } else {
        // DisplayFragment (Fragment B) is in the layout (tablet layout),
        // so tell the fragment to update
        try {
            if (data.get(position).getJSONObject().has("is_album")
                    && data.get(position).getJSONObject().getBoolean("is_album")) {
                ImagesFragment fragment = new ImagesFragment();
                Bundle bundle = new Bundle();
                bundle.putString("imageCall", "3/album/" + data.get(position).getJSONObject().getString("id"));
                bundle.putString("id", data.get(position).getJSONObject().getString("id"));
                bundle.putParcelable("albumData", data.get(position));
                fragment.setArguments(bundle);
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.frame_layout_child, fragment).commitAllowingStateLoss();
            } else {
                SingleImageFragment singleImageFragment = new SingleImageFragment();
                Bundle bundle = new Bundle();
                bundle.putBoolean("gallery", true);
                bundle.putParcelable("imageData", data.get(position));
                singleImageFragment.setArguments(bundle);
                FragmentManager fragmentManager = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.frame_layout_child, singleImageFragment)
                        .commitAllowingStateLoss();
            }
        } catch (JSONException e) {
            Log.e("Error!", e.toString());
        }
    }
}

From source file:com.github.wakhub.monodict.activity.bean.ActivityHelper.java

public void searchOnMainActivity(String query) {
    Intent intent = MainActivity_.intent(activity).get();
    intent.putExtra(SearchManager.QUERY, query);
    intent.setAction(Intent.ACTION_SEARCH);
    activity.startActivity(intent);//from w  w  w. ja  v  a  2  s .co  m
}

From source file:jp.co.conit.sss.sn.ex2.service.SendMessageIdIntentService.java

/**
 * SamuraiNotification????snUserdata???????
 * /*  www  . ja  va  2 s  .c  o  m*/
 * @param snUserdata
 */
private void startActivity4Userdata(String snUserdata) {
    Intent activityIntent = new Intent();
    if (StringUtil.isEmpty(snUserdata) || snUserdata.equals("null")) {
        activityIntent.setClass(getApplicationContext(), MessagesActivity.class);
    } else {
        if (snUserdata.startsWith("http")) {
            activityIntent.setAction(Intent.ACTION_VIEW);
            activityIntent.setData(Uri.parse(snUserdata));
        } else {
            activityIntent.setClass(getApplicationContext(), UserDataActivity.class);
            activityIntent.putExtra("option", snUserdata);
        }
    }
    activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(activityIntent);
}

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

@SuppressWarnings("deprecation")
public Notification createNotification(Bundle settings, JSONObject obj) {

    // notifications[i] = api.normalizeAPI({
    // 'string': {
    // mandatory: ['title', 'body'],
    // defaults: {'icon':'icon'}
    // },//from w  ww.ja v a2 s .co  m
    //
    // 'number': {
    // mandatory: ['id', 'timeMillisSince1970'],
    // // the number of ms after which we start prioritising more recent
    // things above you.
    // defaults: {'epsilon': 1000 * 60 * 24 * 365}
    // },
    //
    // 'boolean': {
    // defaults: {
    // 'vibrate': false,
    // 'sound': false
    // }
    // }

    int icon = settings.getInt("notification_icon", -1);
    if (icon == -1) {
        Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    Notification n = new Notification();
    n.icon = icon;
    n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
    long alarmTime = obj.optLong("timeMillisSince1970");
    long displayTime = obj.optLong("displayTimestamp", alarmTime);
    n.when = displayTime;
    n.tickerText = obj.optString("body");
    n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null);

    if (obj.optBoolean("vibrate")) {
        n.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (obj.optBoolean("sound")) {
        n.defaults |= Notification.DEFAULT_SOUND;
    }

    String uriString = settings.getString("content_uri_prefix");
    if (uriString == null) {
        Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    if (uriString.contains("%d")) {
        uriString = String.format(uriString, obj.optInt("id"));
    }
    Uri uri = Uri.parse(uriString);

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(uri);
    n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT);
    return n;
}