List of usage examples for android.os Bundle keySet
public Set<String> keySet()
From source file:com.intel.xdk.facebook.IntelXDKFacebook.java
private JSONObject BundleToJSON(Bundle bundleObj) { JSONObject jsonObj = new JSONObject(); Object[] keys = bundleObj.keySet().toArray(); for (int i = 0; i < keys.length; i++) { String key = (String) keys[i]; try {// w w w. j av a 2 s .co m jsonObj.put(key, bundleObj.get(key)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return jsonObj; }
From source file:com.onshift.mobile.ExternalReceiver.java
@Override public void onReceive(Context context, Intent intent) { myNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int notificationCount = 1; Bundle extras = intent.getExtras(); StringBuilder payload = new StringBuilder(); StringBuilder messagePayload = new StringBuilder(); StringBuilder message = new StringBuilder(); Gson gson = new Gson(); msgv1 = new PushNotificationMessage_v1(); msg = new PushNotificationMessage(); SharedPreferences settings = context.getSharedPreferences("mysettings", Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); String UserID = settings.getString("UserID", ""); Boolean registrationmsg = false; Boolean displayNotification = false; if (extras != null) { for (String key : extras.keySet()) { if (key.equals("registration_id")) { Log.i("key: ", key); Log.i("value: ", extras.getString(key)); payload.append(String.format("%s=%s", key, extras.getString(key)) + '\n'); MainActivity.sendRegistrationToWebview(extras.getString(key)); registrationmsg = true;// w w w. j a va 2s .co m } if (key.equals("error")) { registrationmsg = true; } if (extras.containsKey("message")) { if ((key.equals("message")) || (key.equals("message_type_id")) || (key.equals("shift_id")) || (key.equals("id")) || (key.equals("recipient_id")) || (key.equals("badge"))) { if (key.equals("message")) { message.append(String.format("%s", extras.getString(key))); msgv1.set_message(extras.getString(key)); } if (key.equals("message_type_id")) { msgv1.set_messagetypeid(extras.getString(key)); } if (key.equals("id")) { msgv1.set_messageid(extras.getString(key)); } if (key.equals("shift_id")) { msgv1.set_shiftid(extras.getString(key)); } if (key.equals("badge")) { msgv1.set_badge(extras.getString(key)); try { notificationCount = Integer.parseInt(extras.getString(key)); } catch (NumberFormatException nfe) { } } if (key.equals("recipient_id")) { if (extras.getString(key).equals(UserID)) { displayNotification = true; } } } } if (extras.containsKey("msg")) { if ((key.equals("msg")) || (key.equals("msg_type")) || (key.equals("id")) || (key.equals("rid")) || (key.equals("badge"))) { if (key.equals("msg")) { message.append(String.format("%s", extras.getString(key))); msg.set_message(extras.getString(key)); } if (key.equals("msg_type")) { msg.set_msgtype(extras.getString(key)); } if (key.equals("id")) { msg.set_messageid(extras.getString(key)); } if (key.equals("badge")) { msg.set_badge(extras.getString(key)); try { notificationCount = Integer.parseInt(extras.getString(key)); } catch (NumberFormatException nfe) { } } if (key.equals("rid")) { if (extras.getString(key).equals(UserID)) { displayNotification = true; } } } } } if (msgv1.get_message() != null) { messagePayload.append(gson.toJson(msgv1)); } if (msg.get_message() != null) { messagePayload.append(gson.toJson(msg)); } try { if (messagePayload.toString() != null) { if (!registrationmsg) { if (displayNotification) { MainActivity.sendForegroundNotificationToWebview(messagePayload.toString()); } } } } catch (Exception e) { } } if (notificationCount > 1) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("OnShift Mobile") .setContentText(String.valueOf(notificationCount) + MESSAGETEMPLATE) .setDefaults(Notification.DEFAULT_VIBRATE); // Intent resultIntent = new Intent(context, MainActivity.class); Intent resultIntent = new Intent(context, UniversalLoginActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); if (messagePayload.toString() != null) { resultIntent.putExtra("message", messagePayload.toString()); editor.putString("PendingMessage", messagePayload.toString()); editor.commit(); } // The stack builder object will contain an artificial back stack // for the // started Activity. // This ensures that navigating backward from the Activity leads out // of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(UniversalLoginActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. if (displayNotification) { mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } } else { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("OnShift Mobile").setContentText(message) .setDefaults(Notification.DEFAULT_VIBRATE); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, UniversalLoginActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); if (messagePayload.toString() != null) { resultIntent.putExtra("message", messagePayload.toString()); editor.putString("PendingMessage", messagePayload.toString()); editor.commit(); } TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(UniversalLoginActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (!registrationmsg) { if (displayNotification) { mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } } } }
From source file:gowtham.com.desknote.MyListener.java
@Override public void onNotificationPosted(StatusBarNotification sbn) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); // If user has disabled notifications, then skip if (!pref.getBoolean("send_notifications", false)) return;/*w ww . j a v a 2 s .c om*/ // Look for our device Set<String> emptySet = new HashSet<String>(); Collection<String> addresses = pref.getStringSet("desktop_address", emptySet); Log.i(MainActivity.TAG, "Connected devices " + connectedDevices); Collection<String> connectedAddresses = getConnectedAddresses(addresses, connectedDevices); Notification mNotification = sbn.getNotification(); // Can't do much if we get a null! if (mNotification == null) return; Bundle extras = mNotification.extras; String packageName = sbn.getPackageName(); String title = extras.getString(Notification.EXTRA_TITLE); String text = extras.getString(Notification.EXTRA_TEXT); String subText = extras.getString(Notification.EXTRA_SUB_TEXT); Integer smallIconID = extras.getInt(Notification.EXTRA_SMALL_ICON); String icon = "null"; if (pref.getBoolean("include_images", false)) { if (extras.getParcelable(Notification.EXTRA_LARGE_ICON) != null) { Bitmap b = Bitmap.class.cast(extras.getParcelable(Notification.EXTRA_LARGE_ICON)); icon = bitmap2Base64(b); } else { icon = getIcon(packageName, smallIconID); } } Map<String, String> extrasMap = new HashMap<String, String>(); for (String key : extras.keySet()) { extrasMap.put(key, String.valueOf(extras.get(key))); } Log.e(MainActivity.TAG, "Got a new notification " + title + " " + mNotification.hashCode()); Message msg = new Message(title, text, subText, icon, mNotification.toString(), extrasMap, packageName); NotificationTransmitter tx = new NotificationTransmitter(); Log.e(MainActivity.TAG, "Sending bluetooth message"); tx.transmit(connectedAddresses, msg); }
From source file:com.facebook.GraphRequest.java
private static void serializeParameters(Bundle bundle, Serializer serializer, GraphRequest request) throws IOException { Set<String> keys = bundle.keySet(); for (String key : keys) { Object value = bundle.get(key); if (isSupportedParameterType(value)) { serializer.writeObject(key, value, request); }//from ww w .j ava 2s . c om } }
From source file:org.zywx.wbpalmstar.engine.universalex.EUExWidget.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == LOADAPP_RQ_CODE) { JSONObject json = new JSONObject(); JSONObject jValue = new JSONObject(); try {//from w w w.j a v a 2 s. c o m if (null != data) { Bundle bundle = data.getExtras(); if (null != bundle) { Set<String> keys = bundle.keySet(); if (null != keys) { for (String key : keys) { Object value = bundle.get(key); jValue.put(key, value); } } } } } catch (Exception e) { e.printStackTrace(); } try { json.put("value", jValue); if (resultCode == Activity.RESULT_OK) { json.put("resultCode", 1); } else { json.put("resultCode", 0); } } catch (Exception e) { e.printStackTrace(); } jsCallback(function_loadApp, 0, EUExCallback.F_C_JSON, json.toString()); } }
From source file:com.playtech.ezpush.gcm.GcmIntentService.java
private void showNotification(Bundle extras) { Intent intent = new Intent(getApplicationContext(), MainActivity.class); NotificationManager notificationManager = (NotificationManager) this .getSystemService(this.NOTIFICATION_SERVICE); CharSequence message = extras.getString(EXTRA_MESSAGE); intent.putExtra(NOTIFICATION_MESSAGE, message); CharSequence title = extras.getString(EXTRA_HEADER); if (title == null) title = NOTIFICATION_TITLE;/* w w w . jav a 2 s. co m*/ String aid = extras.getString("application_id"); intent.putExtra("APP_ID", aid); String nid = extras.getString("nid"); intent.putExtra("NOTIFICATION_ID", nid); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); Notification.InboxStyle style = new Notification.InboxStyle(); style.addLine(message); for (String s : extras.keySet()) { if (!containsKey(s)) { style.addLine(s + ":" + extras.getString(s)); } } PendingIntent pendingIntent = PendingIntent.getActivity(this, intent.hashCode(), intent, PendingIntent.FLAG_ONE_SHOT); Notification.Builder nb = new Notification.Builder(this).setContentTitle(title).setContentText(message) .setSmallIcon(R.mipmap.ezpush_logo) .setLargeIcon(loadBitmap("http://ursynoteka.pl/wp-content/uploads/2012/04/message_new.png")) .setStyle(style).setContentIntent(pendingIntent).setAutoCancel(true); if (extras.containsKey(EXTRA_SOUND)) { nb.setSound(Uri.parse(extras.getString(EXTRA_SOUND))); } if (extras.containsKey(EXTRA_BANNER)) { Bitmap bitmap = loadBitmap(extras.getString(EXTRA_BANNER)); if (bitmap != null) { NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle() .setBigContentTitle(NOTIFICATION_TITLE).setSummaryText(message).bigPicture(bitmap); } } if (extras.containsKey(EXTRA_ICON)) { String iconUrl = extras.getString(EXTRA_ICON); Bitmap bitmap = loadBitmap(iconUrl); if (bitmap != null) { nb.setLargeIcon(bitmap); } } Notification notification = nb.build(); notificationManager.notify(notification.hashCode(), notification); }
From source file:com.canappi.connector.yp.yhere.CouponView.java
public void viewDidLoad() { Bundle extras = getIntent().getExtras(); if (extras != null) { Set<String> keys = extras.keySet(); for (Iterator<String> iter = keys.iterator(); iter.hasNext();) { String key = iter.next(); Class c = SearchView.class; try { Field f = c.getDeclaredField(key); Object extra = extras.get(key); String value = extra.toString(); f.set(this, extras.getString(value)); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace();// w w w.ja v a 2s . co m } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else { } couponViewIds = new HashMap(); couponViewValues = new HashMap(); isUserDefault = false; resultsListView = (ListView) findViewById(R.id.resultsTable); resultsAdapter = new ResultsEfficientAdapter(this); businessNameArray = new ArrayList<String>(); couponDescriptionArray = new ArrayList<String>(); couponIdArray = new ArrayList<String>(); phoneNumberArray = new ArrayList<String>(); callArray = new ArrayList<String>(); streetArray = new ArrayList<String>(); cityArray = new ArrayList<String>(); resultsListView.setAdapter(resultsAdapter); didSelectViewController(); }
From source file:org.cocos2dx.plugin.ShareFacebook.java
private void WebRequestDialog(JSONObject info) throws JSONException { String message = null;/*from ww w . jav a2s . c o m*/ String app_id = null; RequestsDialogBuilder requestDialogBuilder = new WebDialog.RequestsDialogBuilder(mContext); // some property need to add if ((message = safeGetJsonString(info, "message")) == null) { ShareWrapper.onShareResult(mAdapter, ShareWrapper.SHARERESULT_FAIL, "{ \"error_message\" : \" need to add property 'message' \"}"); return; } requestDialogBuilder.setMessage(message); // some property can be choose String to = null; if ((to = safeGetJsonString(info, "to")) != null) requestDialogBuilder.setTo(to); String title = null; if ((title = safeGetJsonString(info, "title")) != null) requestDialogBuilder.setTitle(title); String data = null; if ((data = safeGetJsonString(info, "data")) != null) requestDialogBuilder.setData(data); requestDialogBuilder.setOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(Bundle values, FacebookException error) { if (null != error) { StringBuffer buffer = new StringBuffer(); buffer.append("{\"error_message\":\"").append(error.getMessage()).append("\"}"); ShareWrapper.onShareResult(mAdapter, ShareWrapper.SHARERESULT_FAIL, buffer.toString()); } else { StringBuffer buffer = new StringBuffer(); buffer.append("{\"request\":\""); buffer.append(values.getString("request")); buffer.append("\", \"to\":["); Set<String> keys = values.keySet(); Iterator<String> it = keys.iterator(); while (it.hasNext()) { String key = it.next(); if (!"request".equals(key)) { buffer.append("\""); buffer.append(values.getString(it.next())); buffer.append("\","); } } //remove the last , buffer.deleteCharAt(buffer.length() - 1); buffer.append("]}"); ShareWrapper.onShareResult(mAdapter, ShareWrapper.SHARERESULT_SUCCESS, buffer.toString()); } } }); requestDialogBuilder.build().show(); }
From source file:com.vinaysshenoy.easyoauth.factory.OAuthFactory.java
public InputStream executeRequestForInputStream(HttpRequestTypes requestType, String requestUrl, Bundle params) throws OAuthFactoryException, OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IllegalStateException, IOException { if (accessToken == null) { throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.OAUTH_NOT_AUTHORIZED); }//w ww . j a va 2 s. c om StringBuilder requestParamsBuilder; switch (requestType) { case GET: HttpGet get = null; requestParamsBuilder = new StringBuilder('?'); if (params != null && params.size() > 0) { Set<String> keySet = params.keySet(); Iterator<String> keyIterator = keySet.iterator(); String curKey; while (keyIterator.hasNext()) { curKey = keyIterator.next(); requestParamsBuilder.append(curKey).append('=').append(params.get(curKey)); requestParamsBuilder.append('&'); } } switch (oAuthConfig.oAuthType) { case OAUTH_1_0_A: if (requestParamsBuilder.lastIndexOf("&") != -1) requestParamsBuilder.deleteCharAt(requestParamsBuilder.length() - 1); get = new HttpGet(requestUrl + requestParamsBuilder.toString()); signHttpRequest(get); break; case OAUTH_2_0: requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken()); get = new HttpGet(requestUrl + requestParamsBuilder.toString()); break; } return httpManager.executeHttpRequestForStreamResponse(get); case POST: HttpPost post = null; List<NameValuePair> postParams = null; if (params != null && params.size() > 0) { Set<String> keySet = params.keySet(); Iterator<String> keyIterator = keySet.iterator(); String curKey; postParams = new ArrayList<NameValuePair>(params.size()); while (keyIterator.hasNext()) { curKey = keyIterator.next(); postParams.add(new BasicNameValuePair(curKey, params.getString(curKey))); } } switch (oAuthConfig.oAuthType) { case OAUTH_1_0_A: post = new HttpPost(requestUrl); signHttpRequest(post); break; case OAUTH_2_0: requestParamsBuilder = new StringBuilder('?'); requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken()); post = new HttpPost(requestUrl + requestParamsBuilder.toString()); break; } post.setEntity(new UrlEncodedFormEntity(postParams)); return httpManager.executeHttpRequestForStreamResponse(post); default: throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.UNSUPPORTED_METHOD); } }
From source file:com.vinaysshenoy.easyoauth.factory.OAuthFactory.java
public String executeRequestForString(HttpRequestTypes requestType, String requestUrl, Bundle params) throws OAuthFactoryException, OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IllegalStateException, IOException { if (accessToken == null) { throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.OAUTH_NOT_AUTHORIZED); }// w w w .j a va2 s .c o m StringBuilder requestParamsBuilder; switch (requestType) { case GET: HttpGet get = null; requestParamsBuilder = new StringBuilder('?'); if (params != null && params.size() > 0) { Set<String> keySet = params.keySet(); Iterator<String> keyIterator = keySet.iterator(); String curKey; while (keyIterator.hasNext()) { curKey = keyIterator.next(); requestParamsBuilder.append(curKey).append('=').append(params.get(curKey)); requestParamsBuilder.append('&'); } } switch (oAuthConfig.oAuthType) { case OAUTH_1_0_A: if (requestParamsBuilder.lastIndexOf("&") != -1) requestParamsBuilder.deleteCharAt(requestParamsBuilder.length() - 1); get = new HttpGet(requestUrl + requestParamsBuilder.toString()); signHttpRequest(get); break; case OAUTH_2_0: requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken()); get = new HttpGet(requestUrl + requestParamsBuilder.toString()); break; } return httpManager.executeHttpRequestForStringResponse(get); case POST: HttpPost post = null; List<NameValuePair> postParams = null; if (params != null && params.size() > 0) { Set<String> keySet = params.keySet(); Iterator<String> keyIterator = keySet.iterator(); String curKey; postParams = new ArrayList<NameValuePair>(params.size()); while (keyIterator.hasNext()) { curKey = keyIterator.next(); postParams.add(new BasicNameValuePair(curKey, params.getString(curKey))); } } switch (oAuthConfig.oAuthType) { case OAUTH_1_0_A: post = new HttpPost(requestUrl); signHttpRequest(post); break; case OAUTH_2_0: requestParamsBuilder = new StringBuilder('?'); requestParamsBuilder.append(oAuthConfig.oAuthToken).append('=').append(accessToken.getToken()); post = new HttpPost(requestUrl + requestParamsBuilder.toString()); break; } post.setEntity(new UrlEncodedFormEntity(postParams)); return httpManager.executeHttpRequestForStringResponse(post); default: throw new OAuthFactoryException(OAuthFactoryException.OAuthExceptionMessages.UNSUPPORTED_METHOD); } }