List of usage examples for android.content Intent getExtras
public @Nullable Bundle getExtras()
From source file:com.mobage.air.extension.social.common.RemoteNotification_onNewIntent.java
@Override public FREObject call(final FREContext context, FREObject[] args) { try {//from w ww.j ava2 s . c om Intent intent = context.getActivity().getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { RemoteNotificationPayload payload = RemoteNotification .extractPayloadFromIntent(context.getActivity().getIntent()); JSONArray jsonArgs = new JSONArray(); jsonArgs.put(Convert.customRemotePayloadToJSON(payload, "Inactive")); Dispatcher.dispatch(context, "PlatformListener.handleReceive", jsonArgs); } } } catch (Exception e) { Dispatcher.exception(context, e); } return null; }
From source file:com.pushnotificationsapp.app.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle Log.d("RECEIVED MESSAGE", String.valueOf(extras)); try {//ww w.j a v a 2 s . c o m String data = extras.getString("data"); JSONObject obj = new JSONObject(data); the_message = obj.getString("the_message"); String other_parameters = obj.getString("param2"); Log.v("other parameters found", other_parameters); } catch (Exception e) { e.printStackTrace(); } if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(1000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification(the_message); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:eu.trentorise.smartcampus.launcher.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK) { String token = data.getExtras().getString(AccountManager.KEY_AUTHTOKEN); if (token == null) { Toast.makeText(this, getString(R.string.auth_failed), Toast.LENGTH_SHORT).show(); }/*from w ww . j a v a 2 s . co m*/ } else { Toast.makeText(this, getString(R.string.token_required), Toast.LENGTH_LONG).show(); finish(); } super.onActivityResult(requestCode, resultCode, data); }
From source file:sg.macbuntu.android.pushcontacts.SmsReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null;/*from w ww .j a v a 2 s .c o m*/ String contact = ""; String sender = ""; String body = ""; String account = ""; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean pushPreference = prefs.getBoolean("cbPush", true); if (pushPreference) { if (bundle != null && accountExist(context)) { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; msgs[0] = SmsMessage.createFromPdu((byte[]) pdus[0]); contact = msgs[0].getOriginatingAddress(); body = msgs[0].getMessageBody().toString(); account = getAccount(context); sender = getNameFromPhoneNumber(context, contact); Toast.makeText(context, R.string.toast_push, Toast.LENGTH_LONG).show(); postData(account, contact, body, sender); } } }
From source file:edu.cmu.sei.cloudlet.client.ska.adb.InDataService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.v(TAG, "Received data."); Bundle extras = intent.getExtras(); Log.v(TAG, "Number of items: " + extras.size()); JSONObject jsonData = new JSONObject(); for (String key : extras.keySet()) { try {//from w w w . j a va 2 s. c o m jsonData.put(key, extras.getString(key)); } catch (JSONException e) { e.printStackTrace(); } } String result = mDataHandler.handleData(jsonData, this); Log.v(TAG, "Writing result to file."); FileHandler.writeToFile(ADBConstants.OUT_FILE_PATH, result); Log.v(TAG, "Finished writing result to file."); // We don't need this service to run anymore. stopSelf(); return START_NOT_STICKY; }
From source file:com.lvlstudios.android.gtmessage.C2DMReceiver.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { String url = (String) extras.get("url"); String title = (String) extras.get("title"); String sel = (String) extras.get("sel"); String debug = (String) extras.get("debug"); Log.d(TAG, String.format("C2DMReceiver.onMessage: url='%s', title='%s', sel='%s'", url, title, sel)); if (debug != null) { // server-controlled debug - the server wants to know we received the message, and when. // This is not user-controllable, // we don't want extra traffic on the server or phone. Server may // turn this on for a small percentage of requests or for users // who report issues. DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(AppEngineClient.BASE_URL + "/debug?id=" + extras.get("collapse_key")); // No auth - the purpose is only to generate a log/confirm delivery // (to avoid overhead of getting the token) try { client.execute(get);//from www . j av a 2 s . c o m } catch (ClientProtocolException e) { // ignore } catch (IOException e) { // ignore } } if (title != null && url != null && url.startsWith("http")) { SharedPreferences settings = Prefs.get(context); Intent launchIntent = LauncherUtils.getLaunchIntent(context, title, url, sel); // Notify and optionally start activity if (settings.getBoolean("launchBrowserOrMaps", true) && launchIntent != null) { try { context.startActivity(launchIntent); LauncherUtils.playNotificationSound(context); } catch (ActivityNotFoundException e) { return; } } else { if (sel != null && sel.length() > 0) { // have selection LauncherUtils.generateNotification(context, sel, context.getString(R.string.copied_desktop_clipboard), launchIntent); } else { LauncherUtils.generateNotification(context, url, title, launchIntent); } } // Record history (for link/maps only) if (launchIntent != null && launchIntent.getAction().equals(Intent.ACTION_VIEW)) { HistoryDatabase.get(context).insertHistory(title, url); } } } }
From source file:edu.cmu.sei.cloudlet.client.ska.adb.OutDataService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.v(TAG, "Received data request."); Bundle extras = intent.getExtras(); Log.v(TAG, "Number of items requested: " + extras.size()); JSONObject jsonData = new JSONObject(); for (String key : extras.keySet()) { try {//from ww w . java 2 s . co m jsonData.put(key, extras.getString(key)); } catch (JSONException e) { e.printStackTrace(); } } String jsonDataAsString = mDataHandler.getData(jsonData, this); Log.v(TAG, "Writing to file."); FileHandler.writeToFile(ADBConstants.OUT_FILE_PATH, jsonDataAsString); Log.v(TAG, "Finished writing to file."); // We don't need this service to run anymore. stopSelf(); return START_NOT_STICKY; }
From source file:pj.rozkladWKD.C2DMReceiver.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (!Prefs.get(context).getBoolean(Prefs.PUSH_TURNED_ON, true)) { RozkladWKDApplication app = (RozkladWKDApplication) getApplication(); SharedPreferences.Editor edit = Prefs.get(context).edit(); edit.putBoolean(Prefs.PUSH_TURNED_ON, false); edit.commit();/*from w w w . ja va2 s . co m*/ app.registerPushes(); } else { if (extras != null) { String type = (String) extras.get("type"); String msg = (String) extras.get("msg"); String username = (String) extras.get("usr"); if (RozkladWKD.DEBUG_LOG) { Log.d("PUSH", type + ": " + msg); } String[] categories = Prefs.getStringArray(context, Prefs.PUSH_CATEGORIES, Prefs.DEFAULT_PUSH_CATEGORIES); Prefs.getNotificationMessageNextNumber(context, type); if (!username.equals(Prefs.get(context).getString(Prefs.USERNAME, "")) && categories != null && type != null) { for (String category : categories) { if (type.equals(category)) { Intent notificationIntent = new Intent(this, MessageActivity.class); notificationIntent.putExtra("page", type.equals(MessagesPagerAdapter.MESSAGE_EVENTS) ? 0 : (type.equals(MessagesPagerAdapter.MESSAGE_WKD) ? 1 : 2)); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); showNotification(msg, String.format(getString(R.string.new_message), getResources().getString(getResources().getIdentifier(type, "string", context.getPackageName()))), msg, contentIntent, Prefs.getNotificationMessageNextNumber(context)); break; } } } context.sendBroadcast(new Intent("com.google.ctp.UPDATE_UI")); } } }
From source file:fr.julienvermet.bugdroid.service.ProductsIntentService.java
private void sendResult(Intent intent, ArrayList<Product> products) { Bundle extras = intent.getExtras(); Messenger messenger = (Messenger) extras.get(MESSENGER); if (messenger != null) { Message msg = Message.obtain();//from ww w . j a v a 2s .com Bundle data = new Bundle(); data.putSerializable(PRODUCTS, products); msg.setData(data); try { messenger.send(msg); } catch (android.os.RemoteException e1) { Log.w(getClass().getName(), "Exception sending message", e1); } } }
From source file:com.qurater.pivotal.gcm.GcmIntentServiceV2.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (extras != null && !extras.isEmpty()) { // has effect of unparcelling Bundle /*//ww w. j ava2 s . c o m * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. /* for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } }*/ Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification(extras); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }