List of usage examples for android.content Intent getExtras
public @Nullable Bundle getExtras()
From source file:fr.julienvermet.bugdroid.service.ProductsIntentService.java
@Override protected void onHandleIntent(Intent intent) { Context context = getApplicationContext(); Bundle bundle = intent.getExtras(); String query = bundle.getString(QUERY); int instances_id = bundle.getInt(INSTANCES_ID); int accounts_id = bundle.getInt(ACCOUNTS_ID, -1); boolean forceReload = bundle.getBoolean(FORCE_RELOAD); ArrayList<Product> products = null; if (!forceReload) { String selection = Products.Columns.INSTANCES_ID.getName() + "=" + instances_id + " AND " + Products.Columns.ACCOUNTS_ID.getName() + "=" + accounts_id; String sortOrder = Products.Columns.NAME.getName(); Cursor cursor = context.getContentResolver().query(Products.CONTENT_URI, Products.PROJECTION, selection, null, sortOrder);// ww w . ja va 2 s .co m if (cursor.getCount() > 0) { products = new ArrayList<Product>(); for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); Product product = Product.toProduct(cursor); products.add(product); } sendResult(intent, products); return; } cursor.close(); } String jsonString = NetworkUtils.readJson(query).result; products = parse(jsonString); sendResult(intent, products); // Delete old products for instance String selection = Products.Columns.INSTANCES_ID + "=" + instances_id + " AND " + Products.Columns.ACCOUNTS_ID.getName() + "=" + accounts_id; context.getContentResolver().delete(Products.CONTENT_URI, selection, null); context.getContentResolver().bulkInsert(Products.CONTENT_URI, Product.toContentValues(products, instances_id, accounts_id)); }
From source file:com.notifry.android.C2DMReceiver.java
protected void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras(); // The server would have sent a message type. String type = extras.getString("type"); if (type.equals("message")) { // Fetch the message out into a NotifryMessage object. try {//from w ww . j a v a 2 s. c o m NotifryMessage message = NotifryMessage.fromC2DM(context, extras); Log.d("Notifry", "We've been notifried! " + message.getMessage()); // Persist this message to the database. message.save(context); // Send a notification to the notification service, which will then // dispatch and handle everything else. Intent intentData = new Intent(getBaseContext(), NotificationService.class); intentData.putExtra("messageId", message.getId()); intentData.putExtra("operation", "notifry"); startService(intentData); } catch (ParseException ex) { // Failed to parse a Long. Log.e(TAG, "Failed to parse a long - malformed message from server: " + ex.getMessage()); } catch (NotifryMessage.UnsourceableMessage ex) { // Hmm... a message there was no way to find a source for. // Don't do anything - but do log it. Long accountId = Long.parseLong(extras.getString("device_id")); Long sourceId = Long.parseLong(extras.getString("source_id")); Log.d(TAG, "Unsourceable message: source ID " + sourceId + " device ID " + accountId); } } else if (type.equals("refreshall")) { // Server says to refresh our list when we can. Typically means that // a source has been deleted. Make a note of it. Long serverAccountId = Long.parseLong(extras.getString("device_id")); NotifryAccount account = NotifryAccount.FACTORY.getByServerId(context, serverAccountId); // Assuming it was found... if (account != null) { account.setRequiresSync(true); account.save(context); } Log.d(TAG, "Server just asked us to refresh sources list - usually due to deletion."); } else if (type.equals("sourcechange")) { // Server says that a source has been created or updated. // We should pull a copy of it locally. Long serverSourceId = Long.parseLong(extras.getString("id")); Long serverDeviceId = Long.parseLong(extras.getString("device_id")); Intent intentData = new Intent(getBaseContext(), UpdaterService.class); intentData.putExtra("type", "sourcechange"); intentData.putExtra("sourceId", serverSourceId); intentData.putExtra("deviceId", serverDeviceId); startService(intentData); Log.d(TAG, "Server just asked us to update/create server source ID " + serverSourceId + " for server account ID " + serverDeviceId); } else if (type.equals("devicedelete")) { // Server says we've been deregistered. We should now clear our registration. Long deviceId = Long.parseLong(extras.getString("device_id")); NotifryAccount account = NotifryAccount.FACTORY.getByServerId(context, deviceId); // Check if it's NULL - it's possible we have a desync! if (account != null) { // Disable it, and clear the registration ID. account.setEnabled(false); account.setServerRegistrationId(null); account.setRequiresSync(true); // Save it back to the database. account.save(context); } Log.d(TAG, "Server just asked us to deregister! And should be done now."); } }
From source file:com.liferay.alerts.service.PushNotificationService.java
@Override protected void onHandleIntent(Intent intent) { GoogleCloudMessaging gcm = GCMUtil.getGoogleCloudMessaging(this); String type = gcm.getMessageType(intent); Bundle extras = intent.getExtras(); if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(type) && !extras.isEmpty()) { try {/*from w ww.ja v a2 s . c o m*/ User user = new User(extras.getString("fromUser")); Alert alert = new Alert(user, extras.getString(Alert.PAYLOAD)); _insert(user, alert); _addCard(alert); } catch (JSONException je) { } } PushNotificationReceiver.completeWakefulIntent(intent); }
From source file:com.example.week04.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 /*//from ww w . j a v a 2s.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)) { // TODO :: check wifi-stat // Receive articles, and post notification of received message. String keyword = extras.getString("new data"); getArticleInBackground(keyword); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.google.android.apps.chrometophone.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"); 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(DeviceRegistrar.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 w ww . j a va2 s . c om } catch (ClientProtocolException e) { // ignore } catch (IOException e) { // ignore } } if (title != null && url != null && url.startsWith("http")) { SharedPreferences settings = Prefs.get(context); Intent launchIntent = getLaunchIntent(context, url, title, sel); if (settings.getBoolean("launchBrowserOrMaps", true) && launchIntent != null) { playNotificationSound(context); context.startActivity(launchIntent); } else { if (sel != null && sel.length() > 0) { // have selection generateNotification(context, sel, context.getString(R.string.copied_desktop_clipboard), launchIntent); } else { generateNotification(context, url, title, launchIntent); } } } } }
From source file:com.appnexus.opensdk.InstallTrackerPixel.java
@Override public void onReceive(Context context, final Intent intent) { this.context = context; Clog.error_context = context;/*from ww w.j ava2 s .c om*/ Bundle extras = intent.getExtras(); new PixelHttpTask(0).execute(extras); // new Thread(new RequestRunnable(extras)).start(); }
From source file:com.mgalgs.trackthatthing.LocationReceiver.java
@Override public void onReceive(Context context, Intent intent) { mContext = context;/*from w ww. j av a 2 s. c o m*/ Location loc = (Location) intent.getExtras().get(LocationPoller.EXTRA_LOCATION); if (loc == null) { msg = intent.getStringExtra(LocationPoller.EXTRA_ERROR); } else { SharedPreferences settings = context.getSharedPreferences(TrackThatThing.PREFS_NAME, Context.MODE_PRIVATE); long sleep_period = settings.getLong(TrackThatThing.PREF_SLEEP_TIME, TrackThatThing.DEFAULT_SLEEP_TIME); if (getTimeSinceLastLoc_S() > sleep_period - 3 || mLastLocTime == -1) { // it has been long enough } else { // it hasn't been long enough! Log.d(TrackThatThing.TAG, "It has only been " + getTimeSinceLastLoc_S() + " seconds since the last location update, not long enough!"); return; } mLastLocTime = SystemClock.elapsedRealtime(); float acc = loc.getAccuracy(); double lat = loc.getLatitude(); double lon = loc.getLongitude(); float speed = loc.getSpeed(); String secret_code = settings.getString(TrackThatThing.PREF_SECRET_CODE, null); QueryString qs = new QueryString(TrackThatThing.BASE_URL + "/put"); qs.add("secret", secret_code); qs.add("lat", Double.toString(lat)); qs.add("lon", Double.toString(lon)); qs.add("acc", Float.toString(acc)); qs.add("speed", Float.toString(speed)); Runnable r = new MyInternetThread(qs); new Thread(r).start(); msg = loc.toString(); } Log.d(TrackThatThing.TAG, "got this location: " + msg); }
From source file:com.arthackday.killerapp.GCMIntentService.java
@Override protected void onMessage(Context ctxt, Intent message) { Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh GCMessage"); Bundle extras = message.getExtras(); /*//from www .j a va2s.c o m * TO DO! CHANGE WHAT THE MESSAGES DO!! */ for (String key : extras.keySet()) { Log.i(getClass().getSimpleName(), String.format("onMessage: %s=%s", key, extras.getString(key))); if (key.equals(KillerConstants.EXTRA_KEY_AUDIO)) { Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh pushAudio"); Intent i = new Intent(); Log.i("REMOVE BEFORE COMMIT", extras.getString(key)); Bundle bundle = new Bundle(); //Add your data to bundle bundle.putString(KillerConstants.EXTRA_KEY_AUDIO, extras.getString(key)); //Add the bundle to the intent i.putExtras(bundle); i.setClassName("com.arthackday.killerapp", "com.arthackday.killerapp.PushAudio"); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); } if (key.equals(KillerConstants.EXTRA_KEY_PUSHCALL)) { Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh callnumber"); String number = extras.getString(KillerConstants.EXTRA_KEY_PUSHCALL); String uri = "tel:" + number.trim(); Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse(uri)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } } }
From source file:de.appplant.cordova.plugin.localnotification.Receiver.java
@Override public void onReceive(Context context, Intent intent) { Options options = null;/*from ww w.j a va 2 s . c o m*/ Bundle bundle = intent.getExtras(); JSONObject args; try { args = new JSONObject(bundle.getString(OPTIONS)); options = new Options(context).parse(args); } catch (JSONException e) { return; } this.context = context; this.options = options; // The context may got lost if the app was not running before LocalNotification.setContext(context); fireTriggerEvent(); if (options.getInterval() == 0) { LocalNotification.unpersist(options.getId()); } else if (isFirstAlarmInFuture()) { return; } else { LocalNotification.add(options.moveDate(), false); } Builder notification = buildNotification(); showNotification(notification); }
From source file:com.onesignal.NotificationExtenderService.java
private void processIntent(Intent intent) { Bundle bundle = intent.getExtras(); // Service maybe triggered without extras on some Android devices on boot. // https://github.com/OneSignal/OneSignal-Android-SDK/issues/99 if (bundle == null) { OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "No extras sent to NotificationExtenderService in its Intent!\n" + intent); return;// w ww. j a v a 2 s . c om } String jsonStrPayload = bundle.getString("json_payload"); if (jsonStrPayload == null) { OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "json_payload key is nonexistent from bundle passed to NotificationExtenderService: " + bundle); return; } try { currentJsonPayload = new JSONObject(jsonStrPayload); currentlyRestoring = bundle.getBoolean("restoring", false); if (bundle.containsKey("android_notif_id")) { currentBaseOverrideSettings = new OverrideSettings(); currentBaseOverrideSettings.androidNotificationId = bundle.getInt("android_notif_id"); } if (!currentlyRestoring && OneSignal.notValidOrDuplicated(this, currentJsonPayload)) return; restoreTimestamp = bundle.getLong("timestamp"); processJsonObject(currentJsonPayload, currentlyRestoring); } catch (JSONException e) { e.printStackTrace(); } }