List of usage examples for android.os Bundle isEmpty
public boolean isEmpty()
From source file:com.deltadna.android.sdk.notifications.NotificationListenerService.java
@Override public void onMessageReceived(String from, Bundle data) { Log.d(TAG, String.format(Locale.US, "Received message %s from %s", data, from)); if (from == null) { Log.w(TAG, "Message sender is unknown"); } else if (!from.equals(getString(metaData.getInt(MetaData.SENDER_ID)))) { Log.d(TAG, "Not handling message due to sender ID mismatch"); } else if (data == null || data.isEmpty()) { Log.w(TAG, "Message data is null or empty"); } else {/* www.ja va 2 s . co m*/ notify(createNotification(data).build()); } }
From source file:com.bpd.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * * Note that the HTTP method override is used on non-GET requests. (i.e. * requests are made as "POST" with method specified in the body). * * @param url - the resource to open: must be a welformed URL * @param method - the HTTP method to use ("GET", "POST", etc.) * @param params - the query parameter for the URL (e.g. access_token=foo) * @return the URL contents as a String//w w w .j a v a 2 s. co m * @throws MalformedURLException - if the URL format is invalid * @throws IOException - if a network problem occurs */ public static String openUrl(String url, String method, Bundle params) throws MalformedURLException, IOException { // random string as boundary for multi-part http post String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; String endLine = "\r\n"; OutputStream os; // Try to get filename key String filename = params.getString("filename"); // If found if (filename != null) { // Remove from params params.remove("filename"); } if (method.equals("GET")) { url = url + "?" + encodeUrl(params); } Log.d("Facebook-Util", method + " URL: " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK"); if (!method.equals("GET")) { Bundle dataparams = new Bundle(); for (String key : params.keySet()) { if (params.getByteArray(key) != null) { dataparams.putByteArray(key, params.getByteArray(key)); } } // use method override if (!params.containsKey("method")) { params.putString("method", method); } if (params.containsKey("access_token")) { String decoded_token = URLDecoder.decode(params.getString("access_token")); params.putString("access_token", decoded_token); } conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Connection", "Keep-Alive"); conn.connect(); os = new BufferedOutputStream(conn.getOutputStream()); os.write(("--" + strBoundary + endLine).getBytes()); os.write((encodePostBody(params, strBoundary)).getBytes()); os.write((endLine + "--" + strBoundary + endLine).getBytes()); if (!dataparams.isEmpty()) { for (String key : dataparams.keySet()) { os.write(("Content-Disposition: form-data; filename=\"" + ((filename != null) ? filename : key) + "\"" + endLine).getBytes()); os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); os.write(dataparams.getByteArray(key)); os.write((endLine + "--" + strBoundary + endLine).getBytes()); } } os.flush(); } String response = ""; try { response = read(conn.getInputStream()); } catch (FileNotFoundException e) { // Error Stream contains JSON that we can parse to a FB error response = read(conn.getErrorStream()); } return response; }
From source file:com.carpool.dj.carpool.model.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 w w w. ja va2s.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("", "Working... " + (i+1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } }*/ //Log.i("", "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. //sendNotification("Received: " + extras.toString()); onMessage(Utils.nowActivity, intent); Log.i("", "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.facebook.android.library.Util.java
/** * Connect to an HTTP URL and return the response as a string. * /*from w ww . ja va 2 s . c o m*/ * Note that the HTTP method override is used on non-GET requests. (i.e. * requests are made as "POST" with method specified in the body). * * @param url * - the resource to open: must be a welformed URL * @param method * - the HTTP method to use ("GET", "POST", etc.) * @param params * - the query parameter for the URL (e.g. access_token=foo) * @return the URL contents as a String * @throws MalformedURLException * - if the URL format is invalid * @throws IOException * - if a network problem occurs */ public static String openUrl(String url, String method, Bundle params) throws MalformedURLException, IOException { // random string as boundary for multi-part http post String strBoundary = "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f"; String endLine = "\r\n"; OutputStream os; if (method.equals("GET")) { url = url + "?" + encodeUrl(params); } Util.logd("Facebook-Util", method + " URL: " + url); HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("User-Agent", System.getProperties().getProperty("http.agent") + " FacebookAndroidSDK"); if (!method.equals("GET")) { Bundle dataparams = new Bundle(); for (String key : params.keySet()) { if (params.get(key) instanceof byte[]) { dataparams.putByteArray(key, params.getByteArray(key)); } } // use method override if (!params.containsKey("method")) { params.putString("method", method); } if (params.containsKey("access_token")) { String decoded_token = URLDecoder.decode(params.getString("access_token")); params.putString("access_token", decoded_token); } conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + strBoundary); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Connection", "Keep-Alive"); conn.connect(); os = new BufferedOutputStream(conn.getOutputStream()); os.write(("--" + strBoundary + endLine).getBytes()); os.write((encodePostBody(params, strBoundary)).getBytes()); os.write((endLine + "--" + strBoundary + endLine).getBytes()); if (!dataparams.isEmpty()) { for (String key : dataparams.keySet()) { os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes()); os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes()); os.write(dataparams.getByteArray(key)); os.write((endLine + "--" + strBoundary + endLine).getBytes()); } } os.flush(); } String response = ""; try { response = read(conn.getInputStream()); } catch (FileNotFoundException e) { // Error Stream contains JSON that we can parse to a FB error response = read(conn.getErrorStream()); } return response; }
From source file:com.testpush.notification.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); Log.d("GCM", "RECEIVE"); if (!extras.isEmpty()) { // has effect of unparcelling Bundle Log.d("GCM", "RECEIVE CONTENT : " + extras.toString()); /*/* w ww . j av a 2s .co 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. // LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); //Criteria criteria = new Criteria(); // String bestProvider = locationManager.getBestProvider(criteria, false); // Location location = locationManager.getLastKnownLocation(bestProvider); // Double lat, lon; //} // Toast.makeText(GcmIntentService.this, "message", Toast.LENGHT_LONG).show(); // Toast mytoast=new Toast(MainActivity.this); // mytoast.setView(view); /// mytoast.setDuration(Toast.LENGTH_LONG); // mytoast.show(); String titre = "Checking the location";// extras.getString("titre"); String message = "the office";// extras.getString("message");} // if (location) { // lat = location.getLatitude(); // lon = location.getLongitude(); //titre = String.valueOf(lat);//"this is my Toast message";// extras.getString("titre"); //message = String.valueOf(lat);//"this is my Toast message";// extras.getString("message"); //String titre = String.valueOf(lat);//"this is my Toast message";// extras.getString("titre"); //String message =String.valueOf(lat);//"this is my Toast message";// extras.getString("message"); String image = extras.getString("image"); String id = extras.getString("id"); Intent dialogIntent = new Intent(this, MainActivity2.class); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(dialogIntent); // startService(new Intent(this, services.class)); //Intent intent2 = new Intent(Intent.ACTION_SEND); //intent2.setType("text/html"); //intent2.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com"); //intent2.putExtra(Intent.EXTRA_SUBJECT, "Subject"); // intent2.putExtra(Intent.EXTRA_TEXT, "I'm email body."); //startActivity(Intent.createChooser(intent2, "Send Email")); //ComponentName location = new ComponentName(LocationService.getPackageName(), //GcmIntentService.class.getName()); // startService(new Intent(this, LocationService.class)); sendNotification(titre, message, image, id); } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:fr.neamar.notiflow.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 /*/* w w w.ja 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, we * ignore any message types we're not interested in. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Notiflow", "Send error: " + extras.toString(), extras); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Notiflow", "Deleted messages on server: " + extras.toString(), extras); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. Boolean isSpecial = extras.containsKey("special"); String flow = extras.getString("flow", ""); String author = extras.getString("author", "???"); String content = extras.getString("content", ""); if (isSpecial) { // Wrap content in <em> tag sendNotification(flow, "<b>" + author + "</b>: <em>" + content + "</em>", extras); } else if (content.startsWith(" ")) { sendNotification(flow, "<b>" + author + "</b>: <tt>" + content + "</tt>", extras); } else { sendNotification(flow, "<b>" + author + "</b>: " + content, extras); } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.pulp.campaigntracker.gcm.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); TLog.v(TAG, "extras : " + extras.toString()); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*/* w w w .j a v a 2s .co 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)) { Log.i(TAG, "Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { Log.i(TAG, "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. if (!mAppPref.getString(ConstantUtils.USER_EMAIL, "").isEmpty() && !mAppPref.getString(ConstantUtils.LOGIN_ID, "").isEmpty()) { GCM mMessage = parseMessageObject(extras.getString(MESSAGE)); // Post notification of received message. sendNotification(mMessage); Log.i(TAG, "Received: " + extras.getString(MESSAGE)); } } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:org.android.gcm.client.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { final SharedPreferences prefs = getSharedPreferences("gcmclient", Context.MODE_PRIVATE); pushpak = prefs.getString("push_pak", ""); pushact = prefs.getString("push_act", ""); final boolean pushon = prefs.getBoolean("push_on", true); final boolean pushnotif = prefs.getBoolean("push_notification", true); if (pushnotif) { final String notifact = prefs.getString("notification_act", ""); 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); // Send a notification. if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*//from w w w . j a va2 s . c om * 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(getString(R.string.send_error) + ": " + extras.toString(), notifact); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification(getString(R.string.deleted) + ": " + extras.toString(), notifact); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. sendNotification( getString(R.string.received, extras.getString("name"), extras.getString("num")), notifact); Log.i(TAG, "Received: " + extras.toString()); } } } // End if push is not enabled. if (!pushon) { // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); return; } final boolean fullwake = prefs.getBoolean("full_wake", false); final boolean endoff = prefs.getBoolean("end_off", true); // Manage the screen. PowerManager mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock mWakeLock = mPowerManager .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); boolean misScreenOn = mPowerManager.isScreenOn(); int mScreenTimeout = 0; if (!misScreenOn) { if (endoff) { // Change the screen timeout setting. mScreenTimeout = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 0); if (mScreenTimeout != 0) { Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 3000); } } // Full wake lock if (fullwake) { mWakeLock.acquire(); } } // Start the activity. try { startActivity(getPushactIntent(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)); // Wait to register. Thread.sleep(REGISTER_DURATION); } catch (android.content.ActivityNotFoundException e) { RING_DURATION = 0; Log.i(TAG, "Activity not started"); } catch (InterruptedException e) { } // Release the wake lock. if (!misScreenOn && fullwake) { mWakeLock.release(); } GcmBroadcastReceiver.completeWakefulIntent(intent); // Restore the screen timeout setting. if (endoff && mScreenTimeout != 0) { try { Thread.sleep(RING_DURATION); } catch (InterruptedException e) { } Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, mScreenTimeout); } }
From source file:com.artech.android.gcm.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 /*// w w w.ja v a 2 s. co 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()); Services.Log.Error(TAG, "Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //sendNotification("Deleted messages on server: " + extras.toString()); Services.Log.Error(TAG, "Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { Log.i(TAG, "Received: " + extras.toString()); // Process the real message onMessageReceive(intent); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.irccloud.android.GCMIntentService.java
@Override protected void onHandleIntent(Intent intent) { if (intent != null) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); if (extras != null && !extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //Log.d("IRCCloud", "Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //Log.d("IRCCloud", "Deleted messages on server: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { if (!IRCCloudApplication.getInstance().getApplicationContext().getSharedPreferences("prefs", 0) .getBoolean("gcm_registered", false)) { String regId = IRCCloudApplication.getInstance().getApplicationContext() .getSharedPreferences("prefs", 0).getString("gcm_reg_id", ""); if (regId.length() > 0) { scheduleUnregisterTimer(100, regId, false); }// w w w . j av a 2 s . c o m } else { //Log.d("IRCCloud", "GCM K/V pairs: " + intent.getExtras().toString()); try { String type = intent.getStringExtra("type"); if (type.equalsIgnoreCase("heartbeat_echo")) { NetworkConnection conn = NetworkConnection.getInstance(); ObjectMapper mapper = new ObjectMapper(); JsonParser parser = mapper.getFactory() .createParser(intent.getStringExtra("seenEids")); JsonNode seenEids = mapper.readTree(parser); Iterator<Map.Entry<String, JsonNode>> iterator = seenEids.fields(); while (iterator.hasNext()) { Map.Entry<String, JsonNode> entry = iterator.next(); JsonNode eids = entry.getValue(); Iterator<Map.Entry<String, JsonNode>> j = eids.fields(); while (j.hasNext()) { Map.Entry<String, JsonNode> eidentry = j.next(); String bid = eidentry.getKey(); long eid = eidentry.getValue().asLong(); if (conn.ready && conn.getState() != NetworkConnection.STATE_CONNECTED) BuffersDataSource.getInstance().updateLastSeenEid(Integer.valueOf(bid), eid); Notifications.getInstance().deleteOldNotifications(Integer.valueOf(bid), eid); Notifications.getInstance().updateLastSeenEid(Integer.valueOf(bid), eid); } } parser.close(); } else { int cid = Integer.valueOf(intent.getStringExtra("cid")); int bid = Integer.valueOf(intent.getStringExtra("bid")); long eid = Long.valueOf(intent.getStringExtra("eid")); if (Notifications.getInstance().getNotification(eid) != null) { Log.e("IRCCloud", "GCM got EID that already exists"); return; } String from = intent.getStringExtra("from_nick"); String msg = intent.getStringExtra("msg"); if (msg != null) msg = ColorFormatter .html_to_spanned(ColorFormatter.irc_to_html(TextUtils.htmlEncode(msg))) .toString(); String chan = intent.getStringExtra("chan"); if (chan == null) chan = ""; String buffer_type = intent.getStringExtra("buffer_type"); String server_name = intent.getStringExtra("server_name"); if (server_name == null || server_name.length() == 0) server_name = intent.getStringExtra("server_hostname"); String network = Notifications.getInstance().getNetwork(cid); if (network == null) Notifications.getInstance().addNetwork(cid, server_name); Notifications.getInstance().addNotification(cid, bid, eid, from, msg, chan, buffer_type, type); if (from == null || from.length() == 0) Notifications.getInstance().showNotifications(server_name + ": " + msg); else if (buffer_type.equals("channel")) { if (type.equals("buffer_me_msg")) Notifications.getInstance() .showNotifications(chan + ": " + from + " " + msg); else Notifications.getInstance() .showNotifications(chan + ": <" + from + "> " + msg); } else { if (type.equals("buffer_me_msg")) Notifications.getInstance().showNotifications(" " + from + " " + msg); else Notifications.getInstance().showNotifications(from + ": " + msg); } } } catch (Exception e) { e.printStackTrace(); Log.w("IRCCloud", "Unable to parse GCM message"); } } } } GCMBroadcastReceiver.completeWakefulIntent(intent); } }