List of usage examples for android.os Bundle isEmpty
public boolean isEmpty()
From source file:edu.mines.letschat.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 a2 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(), "0"); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString(), "0"); // 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. String message = (String) extras.get("message"); messages.add(message); String picture = (String) extras.get("picture"); String senderID = (String) extras.get("sender"); String recipientID = (String) extras.get("recipient"); sendNotification(message, senderID); Log.v(TAG, "Received: " + message); Log.i(TAG, "Received: " + extras.toString()); Intent resultBroadCastIntent = new Intent(); /*set action here*/ resultBroadCastIntent.setAction( edu.mines.letschat.MessageActivity.TextCapitalizeResultReceiver.ACTION_TEXT_CAPITALIZED); /*set intent category as default*/ resultBroadCastIntent.addCategory(Intent.CATEGORY_DEFAULT); /*add data to intent*/ resultBroadCastIntent.putExtra(OUTPUT_TEXT, message); // Log.v(TAG, "Sender id " + senderID + " recieve id " + recipientID); Log.v(TAG, picture); Conversation convo = new Conversation(getApplicationContext(), senderID, recipientID, message, false, picture); convo.save(); if (!picture.isEmpty()) { new DownloadImage(picture).execute(); } /*send broadcast */ sendBroadcast(resultBroadCastIntent); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReviever.completeWakefulIntent(intent); }
From source file:com.binarywalllabs.sendit.managers.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 /*//from w w w . j a v a2 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()); } 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. Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. //sendNotification("Received: " + extras.getString("name") + "\n" + extras.getString("body") + "\n" + extras.getString("type")); String name = extras.getString("name"); String body = extras.getString("body"); String type = extras.getString("type"); // if(type.equals("image")) { // generateImageNotification(name, body); // } // else if(type.equals("text")) // generateMessageNotification(name,body); // else if(type.equals("link")) // generateLinkNotification(name, body); Log.i(TAG, "Received: " + extras.getString("type")); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.pti.mates.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); //sendNotification("Estem fent HandleIntent"); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /*//from w w w. jav a2s . 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)) { //sendNotification("Message type correcte"); // This loop represents the service doing some work. String type = intent.getStringExtra("type"); if (type.equals("message")) { String msg = intent.getStringExtra("data"); String senderid = intent.getStringExtra("sender"); String receiverid = intent.getStringExtra("receiver"); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_TYPE, MessageType.INCOMING.ordinal()); values.put(DataProvider.COL_MESSAGE, msg); values.put(DataProvider.COL_SENDERFBID, senderid); values.put(DataProvider.COL_RECEIVERFBID, receiverid); getApplicationContext().getContentResolver().insert(DataProvider.CONTENT_URI_MESSAGES, values); if (Common.isNotify()) { /*Cursor c = getApplicationContext().getContentResolver().query(DataProvider.CONTENT_URI_PROFILE, null, DataProvider.COL_FBID + "=" + senderid, null, null); int index = c.getColumnIndex(DataProvider.COL_NAME); String sendername; if (index != -1) { sendername = c.getString(index); } else { sendername = "name not available"; } sendNotificationChat("New message from " + sendername,senderid);*/ sendNotificationChat("New message", senderid); } } else if (type.equals("mate")) { //extreure info de la persona necessaria per crear el xat (insertar a la base de dades un nou perfil) //si fa falta cridar la activity per mostrar la info. (perfilActivity??) String userdatajson = intent.getStringExtra("data"); String fbid = getInfoFromJson(userdatajson, "id"); String name = getInfoFromJson(userdatajson, "name"); Log.d("Mate intent service", "fbid = " + fbid + " name = " + name); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_NAME, name); values.put(DataProvider.COL_FBID, fbid); getApplication().getContentResolver().insert(DataProvider.CONTENT_URI_PROFILE, values); sendNotificationMate("New Mate with " + name); } } /*else { String msg = intent.getExtras().toString(); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); String senderid = intent.getStringExtra("sender"); String receiverid = intent.getStringExtra("receiver"); //String senderEmail = intent.getStringExtra(DataProvider.COL_SENDER_EMAIL); //String receiverEmail = intent.getStringExtra(DataProvider.COL_RECEIVER_EMAIL); ContentValues values = new ContentValues(2); values.put(DataProvider.COL_TYPE, MessageType.INCOMING.ordinal()); values.put(DataProvider.COL_MESSAGE, msg); values.put(DataProvider.COL_SENDERFBID, senderid); values.put(DataProvider.COL_RECEIVERFBID, receiverid); getApplicationContext().getContentResolver().insert(DataProvider.CONTENT_URI_MESSAGES, values); if (Common.isNotify()) { sendNotification("New message"); } }*/ } else { //sendNotification("Extras empty"); } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.tws.soul.soulbrown.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.j a va 2s . 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("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) { } } */ String msg = extras.getString("msg"); String pushFlag = extras.getString("pushflag"); int status = extras.getInt("status"); LOG.d("GcmIntentService msg : " + msg + " pushFlag : " + pushFlag + " status : " + status); String decMsg = ""; try { decMsg = URLDecoder.decode(msg, "utf-8"); } catch (Exception e) { decMsg = ""; } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. if (!TextUtils.isEmpty(decMsg)) { sendNotification(decMsg); Intent intentGcm = new Intent(GCM_BROADCAST); intentGcm.putExtra("msg", decMsg); LocalBroadcastManager.getInstance(this).sendBroadcast(intentGcm); // alarm , geofence off if (pushFlag.equals(GcmDefine.PUSH_CHG_ORDER)) { //if( status == 1 ) { LOG.d("GcmIntentService alarm , geofence off"); PrefOrderInfo prefOrderInfo = new PrefOrderInfo(this); prefOrderInfo.setArriveTime(0); prefOrderInfo.setOrderStore(""); AlarmManagerBroadcastReceiver alarmManagerBroadcastReceiver = new AlarmManagerBroadcastReceiver(); alarmManagerBroadcastReceiver.cancelAlarm(this); geofenceClient = new GeofenceClient(this, GeofenceResultHandler); //} } else if (pushFlag.equals(GcmDefine.PUSH_CANCEL_ORDER) || pushFlag.equals(GcmDefine.PUSH_APPROACH_USER) || pushFlag.equals(GcmDefine.PUSH_NEW_ORDER)) { // alarm service call Intent intentSvc = new Intent(this, AlarmNotiService.class); this.startService(intentSvc); } else if (pushFlag.equals(GcmDefine.PUSH_CHG_PUSHKEY)) { setPushStatus(0); } } Log.i(TAG, "Received: " + decMsg); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.trk.aboutme.facebook.android.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//from w ww . j av a 2 s . c o m * @throws MalformedURLException - if the URL format is invalid * @throws IOException - if a network problem occurs */ @Deprecated 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); } Utility.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()) { Object parameter = params.get(key); if (parameter instanceof byte[]) { dataparams.putByteArray(key, (byte[]) parameter); } } // 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.eyekabob.util.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 .java 2s. c om * @throws MalformedURLException - if the URL format is invalid * @throws IOException - if a network problem occurs */ // COFFBR01 MODIFIED 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()) { Object value = params.get(key); if (value instanceof byte[]) { dataparams.putByteArray(key, (byte[]) value); } } // 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.getpillion.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 ww. ja va 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. /*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());*/ Log.d("GcmIntentService", "Got data from upstream " + extras.toString()); if (Konotor.getInstance(getApplicationContext()).isKonotorMessage(intent)) { Log.d("Konotor", "Got konotor message"); Konotor.getInstance(getApplicationContext()).handleGcmOnMessage(intent); return; } String simpleClassName = extras.getString("model_name"); String json = extras.getString("json"); Log.d("GcmIntentService", "json received for update - " + json + " for " + simpleClassName); Gson gson = new Gson(); Intent targetIntent = null; String msg = null; SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constant.PREFS_NAME, 0); if (simpleClassName.equals("Ride")) { //check if ride timing or vehicle info got updated try { Ride updatedRide = gson.fromJson(json, Ride.class); Ride ride = Ride.find(Ride.class, "global_id = ?", String.valueOf(updatedRide.globalId)) .get(0); Ride.updateFromUpstream(updatedRide); targetIntent = new Intent(this, RideInfoActivity.class); targetIntent.putExtra("rideId", ride.getId()); msg = "Ride creator has updated the ride"; } catch (Exception e) { e.printStackTrace(); } } if (simpleClassName.equals("User")) { User.updateFromUpstream(gson.fromJson(json, User.class)); //lets not send notification for user info update } if (simpleClassName.equals("RideUserMapping")) { //this is important RideUserMapping rideUserMapping = gson.fromJson(json, RideUserMapping.class); //we need the ride Ride ride = Ride.find(Ride.class, "global_id = ?", String.valueOf(rideUserMapping.rideId)) .get(0); targetIntent = new Intent(this, RideInfoActivity.class); targetIntent.putExtra("rideId", ride.getId()); RideUserMapping myEntry = RideUserMapping .find(RideUserMapping.class, "ride_id = ? AND user_id = ?", String.valueOf(ride.getId()), String.valueOf(sharedPref.getLong("userId", 0L))) .get(0); RideUserMapping updated = RideUserMapping.updateFromUpstream(ride, rideUserMapping); //broadcast only for ride requester. The flow will not go into the subsequent if because of the user's status if (updated.userId == sharedPref.getLong("userId", 0L)) { switch (updated.status) { case Constant.ACCEPTED: //show to requester msg = "Your ride request is approved"; break; case Constant.REJECTED: //show to the requester - request rejected msg = "Sorry, your request has been rejected"; break; } } //broadcast for everyone if (myEntry.status != Constant.REQUESTED && myEntry.status != Constant.REJECTED && myEntry.status != Constant.CANCELLED) { switch (updated.status) { case Constant.REQUESTED: //show only to owner if (myEntry.isOwner) msg = "New ride request"; break; case Constant.CANCELLED: if (updated.isOwner) { msg = "Owner has cancelled the ride"; //for other active users } else { msg = "One traveller backed out"; //for owner } break; case Constant.CHECKED_IN: //show to all - {traveller} has reached his start point msg = "One traveller has reached his pickup point"; break; case Constant.STARTED: //show to all - ride has been started msg = "Ride has started."; break; } } } if (simpleClassName.equals("WorkHistory")) { //lets just leave this } Log.d("GcmIntentService", "message to the user - " + msg); if (msg != null) sendNotification(targetIntent, msg); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.example.administrator.e_pic.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); String from = extras.getString(TAG_RECEIVED_FROM); int notType = Integer.parseInt(extras.getString(TAG_NOTIFICATION_TYPE)); 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 .j a v a2s .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. /*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(from, notType); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.app.easyblood.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 . j av a 2 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("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)) { type = extras.getString("Type"); intType = Integer.parseInt(type); switch (intType) { case 1: verifyUserId = extras.getString("UserId"); break; case 2: askedby = extras.getString("AskedBy"); category = extras.getString("Category"); repliedby = extras.getString("RepliedBy"); replymessage = extras.getString("ReplyMessage"); userid_questions = extras.getString("UserId"); questionmessage = extras.getString("QuestionMessage"); asked_time_questions = extras.getString("AskedTime"); imagepath = extras.getString("UserProfilePhotoServerPath"); questionid = extras.getString("QuestionId"); userprofession_questions = extras.getString("UserProfession"); break; case 3: //New Request Notification message = extras.getString("message"); requestId = extras.getString("requestId"); username = extras.getString("userName"); break; case 4://New Response Notification message = extras.getString("ResponseMessage"); username = extras.getString("ResponseUserName"); requestId = extras.getString("RequestId"); userId = extras.getString("ResponseUserId"); responseId = extras.getString("ResponseId"); responseUserProfession = extras.getString("Profession"); responseUserProfilePath = extras.getString("ProfilePhotoUrl"); break; case 5: chatChatId = extras.getString("ChatId"); chatMessage = extras.getString("Message"); chatMessageTime = extras.getString("SentOn"); chatSenderId = extras.getString("SenderId"); chatSenderName = extras.getString("UserName"); break; } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.captix.scan.social.facebook.Util.java
/** * Connect to an HTTP URL and return the response as a string. * /*w w w . j a v a2 s. co 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); } 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")) { @SuppressWarnings("deprecation") 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; }