List of usage examples for android.os Bundle isEmpty
public boolean isEmpty()
From source file:com.swisscom.safeconnect.utils.gcm.GcmBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { setResultCode(Activity.RESULT_OK);//from w w w . ja va2 s . c om Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { if (BuildConfig.DEBUG) Log.d(Config.TAG, "Error receiving push notification: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { if (BuildConfig.DEBUG) Log.d(Config.TAG, "Deleted messages on server: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { if (BuildConfig.DEBUG) Log.d(Config.TAG, "Received: " + extras.toString()); String key = extras.getString("key"); String args_json = extras.getString("args"); if (key != null) { int resId = context.getResources().getIdentifier(key, "string", context.getPackageName()); if (resId != 0) { Object[] args = convertJsonToStringArray(args_json); String title = context.getString(R.string.push_title); String msg = context.getString(resId, args); //String title = extras.getString("title"); //String msg = extras.getString("message"); sendNotification(title, msg, context); } } } } }
From source file:br.com.arlsoft.pushclient.PushClientModule.java
public static Intent getLauncherIntent(Bundle extras) { TiApplication appContext = TiApplication.getInstance(); PackageManager pm = appContext.getPackageManager(); Intent launch = pm.getLaunchIntentForPackage(appContext.getPackageName()); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (extras != null && !extras.isEmpty()) { launch.putExtra(PROPERTY_EXTRAS, extras); }//from w w w . j av a 2 s. c o m return launch; }
From source file:com.kasoft.pushnot.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); String title = ""; String post = ""; GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle 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(), "", ""); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { Log.i(TAG, "Received: " + extras.toString()); title = extras.getString("title"); post = extras.getString("post"); sendNotification(title + " " + post, title, post); }/*from w w w . j av a2 s .c o m*/ } GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.kinoma.kinomaplay.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); if ((gcm != null) && !extras.isEmpty()) { try {// ww w. ja va 2 s .com if (messageType.equals(GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR)) { } else if (messageType.equals(GoogleCloudMessaging.MESSAGE_TYPE_DELETED)) { } else { String message = extras.getString("message"); //Log.i("kinoma", "message:" + message); JSONObject json = new JSONObject(message); String jsonString = json.toString(); Log.i("kinoma", "json:" + jsonString); if (KinomaPlay.getLaunched() && KinomaPlay.active) { KinomaPlay.doFskOnRemoteNotification(jsonString); } else { saveMessage(jsonString); sendNotification(json); } } } catch (Exception e) { Log.i("kinoma", "exception"); } } GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.cloudbees.gasp.gcm.GCMIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); try {// w w w . ja va 2 s . c om if (!extras.isEmpty()) { 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()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { Log.i(TAG, "Received: " + extras.toString()); int index = Integer.valueOf(extras.getString("id")); String table = extras.getString("table"); String notificationMessage = "There's something new from Gasp!"; if (table != null) { if (table.matches("reviews")) { startService(new Intent(getApplicationContext(), ReviewUpdateService.class) .putExtra(ConsoleActivity.ResponseReceiver.PARAM_ID, index)); } else if (table.matches("restaurants")) { startService(new Intent(getApplicationContext(), RestaurantUpdateService.class) .putExtra(ConsoleActivity.ResponseReceiver.PARAM_ID, index)); } else if (table.matches("users")) { startService(new Intent(getApplicationContext(), UserUpdateService.class) .putExtra(ConsoleActivity.ResponseReceiver.PARAM_ID, index)); } // Send notification message for message bar display etc sendNotification(notificationMessage); } else { Log.e(TAG, "Error: table not specified"); } // Release the wake lock provided by the WakefulBroadcastReceiver. GCMBroadcastReceiver.completeWakefulIntent(intent); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:net.iamyellow.gcmjs.GCMIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { if (messageType == null) { GcmjsModule.logd(TAG + ": messageType is null"); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { GcmjsModule.logd(TAG + ": deleted"); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { int appIconId = 0; try { appIconId = TiRHelper.getApplicationResource("drawable.appicon"); } catch (ResourceNotFoundException e) { GcmjsModule.logd(TAG + ": ResourceNotFoundException: " + e.getMessage()); }//from w w w. j a v a 2 s .c o m // ????Push if (!isInForeground()) { TiApplication tiapp = TiApplication.getInstance(); Intent launcherIntent = new Intent(tiapp, GcmjsService.class); for (String key : extras.keySet()) { String eventKey = key.startsWith("data.") ? key.substring(5) : key; String data = extras.getString(key); // GcmjsModule.logd(TAG + ": eventKey:" + eventKey + " // data:" + data); if (data != null && !"".equals(data)) { launcherIntent.putExtra(eventKey, data); } } tiapp.startService(launcherIntent); } else { KrollDict messageData = new KrollDict(); for (String key : extras.keySet()) { String eventKey = key.startsWith("data.") ? key.substring(5) : key; String data = extras.getString(key); // GcmjsModule.logd(TAG + ": eventKey:" + eventKey + " // data:" + data); if (data != null && !"".equals(data)) { messageData.put(eventKey, data); } } fireMessage(messageData); } } } GCMBroadcastReceiver.completeWakefulIntent(intent); }
From source file:org.anhonesteffort.flock.ManageSubscriptionActivity.java
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { if (savedInstanceState != null && !savedInstanceState.isEmpty()) { if (!DavAccount.build(savedInstanceState.getBundle(KEY_DAV_ACCOUNT_BUNDLE)).isPresent()) { Log.e(TAG, "where did my dav account bundle go?! :("); finish();/*ww w .ja v a2 s . c om*/ return; } davAccount = DavAccount.build(savedInstanceState.getBundle(KEY_DAV_ACCOUNT_BUNDLE)).get(); currentFragment = savedInstanceState.getInt(KEY_CURRENT_FRAGMENT, -1); activityRequestCode = Optional.fromNullable(savedInstanceState.getInt(KEY_REQUEST_CODE)); activityResultCode = Optional.fromNullable(savedInstanceState.getInt(KEY_RESULT_CODE)); activityResultData = Optional.fromNullable((Intent) savedInstanceState.getParcelable(KEY_RESULT_DATA)); } super.onRestoreInstanceState(savedInstanceState); }
From source file:com.gcm.test.GCMIntentService.java
@Override protected void onHandleIntent(Intent intent) { // TODO Auto-generated method stub Log.i("GCMIntentService", "sending push notification is" + intent.getStringExtra("message")); Bundle extras = intent.getExtras(); String msg = intent.getStringExtra("message"); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { 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(500); } catch (InterruptedException e) { }/*from w w w . j a va 2 s .c om*/ } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. //sendNotification("Received: " + extras.toString()); sendNotification(msg); Log.i(TAG, "Received: " + extras.toString()); } } GCMBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.appdynamics.demo.gasp.gcm.GCMIntentService.java
@Override protected void onHandleIntent(Intent intent) { //AppDynamics CallTracker tracker = Instrumentation.beginCall("GCMIntentService", "onHandleIntent()", intent); Bundle extras = intent.getExtras(); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String messageType = gcm.getMessageType(intent); try {//from www . j a v a2 s.c om if (!extras.isEmpty()) { 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()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { Log.i(TAG, "Received: " + extras.toString()); int index = Integer.valueOf(extras.getString("id")); String table = extras.getString("table"); String notificationMessage = "There's something new from Gasp!"; if (table != null) { if (table.matches("reviews")) { startService(new Intent(getApplicationContext(), ReviewUpdateService.class) .putExtra(PARAM_ID, index)); } else if (table.matches("restaurants")) { startService(new Intent(getApplicationContext(), RestaurantUpdateService.class) .putExtra(PARAM_ID, index)); } else if (table.matches("users")) { startService(new Intent(getApplicationContext(), UserUpdateService.class) .putExtra(PARAM_ID, index)); } // Send notification message for message bar display etc sendNotification(notificationMessage); } else { Log.e(TAG, "Error: table not specified"); } // Release the wake lock provided by the WakefulBroadcastReceiver. GCMBroadcastReceiver.completeWakefulIntent(intent); } } } catch (Exception e) { e.printStackTrace(); } //AppDynamics com.appdynamics.eumagent.runtime.Instrumentation.endCall(tracker); }
From source file:com.hybris.mobile.data.WebServiceDataProvider.java
/** * Synchronous call to the OCC web services * /*ww w . j a v a 2 s . c om*/ * @param url * The url * @param isAuthorizedRequest * Whether this request requires the authorization token sending * @param httpMethod * method type (GET, PUT, POST, DELETE) * @param httpBody * Data to be sent in the body (Can be empty) * @return The data from the server as a string, in almost all cases JSON * @throws MalformedURLException * @throws IOException * @throws ProtocolException */ public static String getResponse(Context context, String url, Boolean isAuthorizedRequest, String httpMethod, Bundle httpBody) throws MalformedURLException, IOException, ProtocolException, JSONException { // Refresh if necessary if (isAuthorizedRequest && WebServiceAuthProvider.tokenExpiredHint(context)) { WebServiceAuthProvider.refreshAccessToken(context); } boolean refreshLimitReached = false; int refreshed = 0; String response = ""; while (!refreshLimitReached) { // If we have refreshed max number of times, we will not do so again if (refreshed == 1) { refreshLimitReached = true; } // Make the connection and get the response OutputStream os; HttpURLConnection connection; if (httpMethod.equals("GET") && httpBody != null && !httpBody.isEmpty()) { url = url + "?" + encodePostBody(httpBody); } URL requestURL = new URL(addParameters(context, url)); if (StringUtils.equalsIgnoreCase(requestURL.getProtocol(), "https")) { trustAllHosts(); HttpsURLConnection https = createSecureConnection(requestURL); https.setHostnameVerifier(DO_NOT_VERIFY); if (isAuthorizedRequest) { String authValue = "Bearer " + SDKSettings.getSharedPreferenceString(context, "access_token"); https.setRequestProperty("Authorization", authValue); } connection = https; } else { connection = createConnection(requestURL); } connection.setRequestMethod(httpMethod); if (!httpMethod.equals("GET") && !httpMethod.equals("DELETE")) { connection.setDoOutput(true); connection.setDoInput(true); connection.connect(); if (httpBody != null && !httpBody.isEmpty()) { os = new BufferedOutputStream(connection.getOutputStream()); os.write(encodePostBody(httpBody).getBytes()); os.flush(); } } response = ""; try { LoggingUtils.d(LOG_TAG, connection.toString()); response = readFromStream(connection.getInputStream()); } catch (FileNotFoundException e) { LoggingUtils.e(LOG_TAG, "Error reading stream \"" + connection.getInputStream() + "\". " + e.getLocalizedMessage(), context); response = readFromStream(connection.getErrorStream()); } finally { connection.disconnect(); } // Allow for calls to return nothing if (response.length() == 0) { return ""; } // Check for JSON parsing errors (will throw JSONException is can't be parsed) JSONObject object = new JSONObject(response); // If no error, return response if (!object.has("error")) { return response; } // If there is a refresh token error, refresh the token else if (object.getString("error").equals("invalid_token")) { if (refreshLimitReached) { // Give up return response; } else { // Refresh the token WebServiceAuthProvider.refreshAccessToken(context); refreshed++; } } } // while(!refreshLimitReached) // There is an error other than a refresh error, so return the response return response; }