List of usage examples for android.content Intent setAction
public @NonNull Intent setAction(@Nullable String action)
From source file:com.gcm.client.GcmHelper.java
/** * Delete the existing push token/* w ww . ja va 2 s.c o m*/ * @param context An instance of the application Context */ public synchronized void deleteToken(Context context) { if (!TextUtils.isEmpty(pushToken)) { Intent registration = new Intent(context, RegistrationIntentService.class); registration.setAction(RegistrationIntentService.ACTION_UNREGISTER); context.startService(registration); SharedPreferences pref = getSharedPreference(context); pref.edit().remove(PREF_KEY_TOKEN).apply(); } }
From source file:com.gcm.client.GcmHelper.java
/** * Subscribe to a list of topics./*from ww w. j a va 2 s.com*/ * * @param context An instance of the application {@link Context} * @return true if it is a new topic */ public boolean subscribeTopic(@NonNull Context context, @NonNull String[] newTopics) { if (!initialized) init(context); if (newTopics.length == 0) return false; if (null == topics) { topics = new ArrayList<>(); } for (String topic : newTopics) { if (topics.contains(topic)) { return false; } topics.add(topic); } saveSubscibedTopics(context); Intent intent = new Intent(context, RegistrationIntentService.class); intent.setAction(RegistrationIntentService.ACTION_SUBSCRIBE); intent.putExtra(RegistrationIntentService.EXTRA_TOPIC_LIST, newTopics); context.startService(intent); return true; }
From source file:com.googlecode.android_scripting.activity.Main.java
protected void broadcastInstallationStateChange(boolean isInterpreterInstalled) { Intent intent = new Intent(); intent.setData(Uri.parse("package:" + mId)); if (isInterpreterInstalled) { intent.setAction(InterpreterConstants.ACTION_INTERPRETER_ADDED); } else {/*from w w w .j av a2 s . com*/ intent.setAction(InterpreterConstants.ACTION_INTERPRETER_REMOVED); } sendBroadcast(intent); }
From source file:net.reichholf.dreamdroid.activities.ServiceListActivity.java
/** * @param title/*from w w w . j a v a2 s.c o m*/ * The program title to find similar programs for */ public void openSimilar(String title) { Log.e("dreamDroid", "title: " + title); Intent intent = new Intent(this, SearchEpgActivity.class); intent.setAction(Intent.ACTION_SEARCH); intent.putExtra(SearchManager.QUERY, title); startActivity(intent); }
From source file:com.esri.arcgisruntime.sample.editfeatureattachments.EditAttachmentActivity.java
private void fetchAttachmentAsync(final int position, final View view) { progressDialog.setTitle(getApplication().getString(R.string.downloading_attachments)); progressDialog.setMessage(getApplication().getString(R.string.wait)); progressDialog.show();//from ww w . j a v a 2 s.c om // create a listenableFuture to fetch the attachment asynchronously final ListenableFuture<InputStream> listenableFuture = attachments.get(position).fetchDataAsync(); listenableFuture.addDoneListener(new Runnable() { @Override public void run() { try { String fileName = attachmentList.get(position); // create a drawable from InputStream Drawable d = Drawable.createFromStream(listenableFuture.get(), fileName); // create a bitmap from drawable Bitmap bitmap = ((BitmapDrawable) d).getBitmap(); File root = Environment.getExternalStorageDirectory(); File fileDir = new File(root.getAbsolutePath() + "/ArcGIS/Attachments"); // create folder /ArcGIS/Attachments in external storage boolean isDirectoryCreated = fileDir.exists(); if (!isDirectoryCreated) { isDirectoryCreated = fileDir.mkdirs(); } File file = null; if (isDirectoryCreated) { file = new File(fileDir, fileName); FileOutputStream fos = new FileOutputStream(file); // compress the bitmap to PNG format bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.flush(); fos.close(); } if (progressDialog.isShowing()) { progressDialog.dismiss(); } // open the file in gallery Intent i = new Intent(); i.setAction(android.content.Intent.ACTION_VIEW); i.setDataAndType(Uri.fromFile(file), "image/png"); startActivity(i); } catch (Exception e) { Log.d(TAG, e.toString()); } } }); }
From source file:com.intel.xdk.camera.Camera.java
private void pickImage() { if (busy) {/*w ww . ja v a2 s . c om*/ cameraBusy(); } busy = true; Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); cordova.startActivityForResult(this, intent, SELECT_PICTURE); }
From source file:com.google.android.apps.santatracker.presentquest.PlacesIntentService.java
@WorkerThread private void getPlaceAndBroadcast(LatLng center, int radius) { long now = System.currentTimeMillis(); boolean useCache = now - mPreferences.getLastPlacesApiRequest() < mConfig.CACHE_REFRESH_MS; // Try and retrieve place from DB cache if CACHE_REFRESH_MS has not elapsed // since last API request. Place place = null;//from w w w .jav a 2s . c o m if (useCache) { place = getCachedPlace(center, radius); } // If CACHE_REFRESH_MS has elapsed, or no nearby places in cache, fetch from API and // cache the results, then return one of them. Guaranteed to have results since we // back-fill with random locations if too few returned from Places API. if (place == null) { // Set the last API request time with a +/- 30 sec jitter. int jitter = ((new Random()).nextInt(60) - 30) * 1000; mPreferences.setLastPlacesApiRequest(now + jitter); Log.d(TAG, "getPlaceAndBroadcast: " + (useCache ? "cache miss" : "cache refresh elapsed")); place = fetchPlacesAndGetCached(center, radius); } else { Log.d(TAG, "getPlaceAndBroadcast: cache hit"); } // If the place is STILL null, just bail if (place == null) { Log.w(TAG, "getPlaceAndBroadcast: total cache failure"); return; } // Log some stats about the place picked int distance = Distance.between(center, place.getLatLng()); Log.d(TAG, "getPlaceAndBroadcast: distance=" + distance + ", used=" + place.used); // Create result intent and broadcast the result. Intent intent = new Intent(); intent.setAction(ACTION_SEARCH_NEARBY); intent.putExtra(EXTRA_PLACE_RESULT, place.getLatLng()); boolean received = LocalBroadcastManager.getInstance(this).sendBroadcast(intent); Log.d(TAG, "getPlaceAndBroadcast: received=" + received); if (received) { // Increments usage counter. place.use(); } }
From source file:com.hybris.mobile.activity.AbstractProductDetailActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean handled = super.onOptionsItemSelected(item); if (!handled) { // Put custom menu items handlers here switch (item.getItemId()) { // NFC writing is for debug use only case R.id.write_tag: if (NFCUtil.canNFC(this)) { Intent writeIntent = new Intent(this, NFCWriteActivity.class); NdefMessage msg = getNDEF(mProduct.getCode()); writeIntent.putExtra(NFCWriteActivity.NDEF_MESSAGE, msg); startActivity(writeIntent); } else { Toast.makeText(this, R.string.error_nfc_not_supported, Toast.LENGTH_LONG).show(); }//from w w w . j ava 2 s. co m return true; case R.id.share: try { Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, mProduct.getName() + " - " + getString(R.string.nfc_url, URLEncoder.encode(mProduct.getCode(), "UTF-8"))); sendIntent.setType("text/plain"); startActivity(Intent.createChooser(sendIntent, getString(R.string.share_dialog_title))); } catch (UnsupportedEncodingException e) { LoggingUtils.e(LOG_TAG, "Error trying to encode product code to UTF-8. " + e.getLocalizedMessage(), Hybris.getAppContext()); } return true; default: return false; } } return handled; }
From source file:com.snappy.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///w w w . j a v a2s. c o m private void generateNotification(Context context, String message, String fromName, Bundle pushExtras, String body) { db = new LocalDB(context); List<LocalMessage> myMessages = db.getAllMessages(); // Open a new activity called GCMMessageView Intent intento = new Intent(this, SplashScreenActivity.class); intento.replaceExtras(pushExtras); // Pass data to the new activity intento.putExtra(Const.PUSH_INTENT, true); intento.setAction(Long.toString(System.currentTimeMillis())); intento.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); // Starts the activity on notification click PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT); // Create the notification with a notification builder NotificationCompat.Builder notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis()) .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)) .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true) .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) .setContentText(body).setContentIntent(pIntent); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)); for (int i = 0; i < myMessages.size(); i++) { inboxStyle.addLine(myMessages.get(i).getMessage()); } notification.setStyle(inboxStyle); // Remove the notification on click //notification.flags |= Notification.FLAG_AUTO_CANCEL; //notification.defaults |= Notification.DEFAULT_VIBRATE; //notification.defaults |= Notification.DEFAULT_SOUND; //notification.defaults |= Notification.DEFAULT_LIGHTS; NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(R.string.app_name, notification.build()); { // Wake Android Device when notification received PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH"); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); } }
From source file:com.achep.base.ui.fragments.dialogs.FeedbackDialog.java
private void send(@NonNull CharSequence title, @NonNull CharSequence body, boolean attachLog) { Activity context = getActivity();/*from w w w .ja va 2 s .c om*/ String[] recipients = { Build.SUPPORT_EMAIL }; Intent intent = new Intent().putExtra(Intent.EXTRA_EMAIL, recipients).putExtra(Intent.EXTRA_SUBJECT, title) .putExtra(Intent.EXTRA_TEXT, body); if (attachLog) { attachLog(intent); intent.setAction(Intent.ACTION_SEND); intent.setType("message/rfc822"); } else { intent.setAction(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); // only email apps should handle it } if (IntentUtils.hasActivityForThat(context, intent)) { startActivity(intent); dismiss(); } else { ToastUtils.showLong(context, R.string.feedback_error_no_app); } }