List of usage examples for android.os Bundle keySet
public Set<String> keySet()
From source file:com.chilliworks.chillisource.core.LocalNotificationReceiver.java
/** * Called when a local notification broad cast is received. Funnels the notification * into the app if open or into the notification bar if not * /*w w w . java2 s . com*/ * @author Steven Hendrie * * @param The context. * @param The intent. */ @SuppressWarnings("deprecation") @Override public void onReceive(Context in_context, Intent in_intent) { //evaluate whether or not the main engine activity is in the foreground boolean isAppInForeground = false; if (CSApplication.get() != null && CSApplication.get().isActive() == true) { isAppInForeground = true; } //if the main engine activity is in the foreground, simply pass the //notification into it. Otherwise display a notification. if (isAppInForeground == true) { final Intent intent = new Intent(in_intent.getAction()); Bundle mapParams = in_intent.getExtras(); Iterator<String> iter = mapParams.keySet().iterator(); while (iter.hasNext()) { String strKey = iter.next(); intent.putExtra(strKey, mapParams.get(strKey).toString()); } LocalNotificationNativeInterface localNotificationNI = (LocalNotificationNativeInterface) CSApplication .get().getSystem(LocalNotificationNativeInterface.InterfaceID); if (localNotificationNI != null) { localNotificationNI.onNotificationReceived(intent); } } else { //aquire a wake lock if (s_wakeLock != null) { s_wakeLock.release(); } PowerManager pm = (PowerManager) in_context.getSystemService(Context.POWER_SERVICE); s_wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "NotificationWakeLock"); s_wakeLock.acquire(); //pull out the information from the intent Bundle params = in_intent.getExtras(); CharSequence title = params.getString(k_paramNameTitle); CharSequence text = params.getString(k_paramNameBody); int intentId = params.getInt(LocalNotification.k_paramNameNotificationId); int paramSize = params.size(); String[] keys = new String[paramSize]; String[] values = new String[paramSize]; Iterator<String> iter = params.keySet().iterator(); int paramNumber = 0; while (iter.hasNext()) { keys[paramNumber] = iter.next(); values[paramNumber] = params.get(keys[paramNumber]).toString(); ++paramNumber; } Intent openAppIntent = new Intent(in_context, CSActivity.class); openAppIntent.setAction("android.intent.action.MAIN"); openAppIntent.addCategory("android.intent.category.LAUNCHER"); openAppIntent.putExtra(k_appOpenedFromNotification, true); openAppIntent.putExtra(k_arrayOfKeysName, keys); openAppIntent.putExtra(k_arrayOfValuesName, values); openAppIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent sContentIntent = PendingIntent.getActivity(in_context, intentId, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIconBitmap = null; int LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify_large"); //Use small icon if no large icon if (LargeIconID == 0) { LargeIconID = ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify"); } if (LargeIconID > 0) { largeIconBitmap = BitmapFactory.decodeResource(in_context.getResources(), LargeIconID); } Notification notification = new NotificationCompat.Builder(in_context).setContentTitle(title) .setContentText(text) .setSmallIcon(ResourceHelper.GetDynamicResourceIDForField(in_context, ResourceHelper.RESOURCE_SUBCLASS.RESOURCE_DRAWABLE, "ic_stat_notify")) .setLargeIcon(largeIconBitmap).setContentIntent(sContentIntent).build(); NotificationManager notificationManager = (NotificationManager) in_context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(intentId, notification); Toast.makeText(in_context, text, Toast.LENGTH_LONG).show(); } }
From source file:org.mozilla.gecko.sync.SynchronizerConfigurations.java
protected HashMap<String, SynchronizerConfiguration> enginesMapFromBundleV1(Bundle engineBundle) throws IOException, ParseException, NonObjectJSONException { HashMap<String, SynchronizerConfiguration> engines = new HashMap<String, SynchronizerConfiguration>(); Set<String> keySet = engineBundle.keySet(); for (String engine : keySet) { String[] values = engineBundle.getStringArray(engine); String syncID = values[0]; RepositorySessionBundle remoteBundle = new RepositorySessionBundle(values[1]); RepositorySessionBundle localBundle = new RepositorySessionBundle(values[2]); engines.put(engine, new SynchronizerConfiguration(syncID, remoteBundle, localBundle)); }//w w w. j ava 2s . c om return engines; }
From source file:org.mozilla.mozstumbler.service.datahandling.StumblerBundle.java
private StumblerBundle(Parcel in) { mWifiData = new HashMap<String, ScanResult>(); mCellData = new HashMap<String, CellInfo>(); Bundle wifiBundle = in.readBundle(ScanResult.class.getClassLoader()); Bundle cellBundle = in.readBundle(CellInfo.class.getClassLoader()); Collection<String> scans = wifiBundle.keySet(); for (String s : scans) { mWifiData.put(s, (ScanResult) wifiBundle.get(s)); }// w w w . j a va 2s . com Collection<String> cells = cellBundle.keySet(); for (String c : cells) { mCellData.put(c, (CellInfo) cellBundle.get(c)); } mGpsPosition = in.readParcelable(Location.class.getClassLoader()); mPhoneType = in.readInt(); }
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//from w w w . j a v a 2 s. c o 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:nuclei.task.TaskGcmService.java
@Override public int onRunTask(TaskParams taskParams) { try {//from ww w . j a va 2s. co m Bundle bundle = taskParams.getExtras(); String taskName = bundle.getString(TaskScheduler.TASK_NAME); Task task = (Task) Class.forName(taskName).newInstance(); ArrayMap<String, Object> map = new ArrayMap<>(bundle.size()); for (String key : bundle.keySet()) { map.put(key, bundle.get(key)); } task.deserialize(map); if (task.isRunning()) return GcmNetworkManager.RESULT_RESCHEDULE; task.attach(null, ContextHandle.getApplicationHandle()); task.run(); task.deliverResult(this); return GcmNetworkManager.RESULT_SUCCESS; } catch (Exception err) { LOG.e("Error running task", err); return GcmNetworkManager.RESULT_FAILURE; } }
From source file:android.support.v17.leanback.widget.ViewsStateBundle.java
public final void loadFromBundle(Bundle savedBundle) { if (mChildStates != null && savedBundle != null) { mChildStates.evictAll();//from w ww . j a v a 2 s . c om for (Iterator<String> i = savedBundle.keySet().iterator(); i.hasNext();) { String key = i.next(); mChildStates.put(key, savedBundle.getSparseParcelableArray(key)); } } }
From source file:com.lingeringsocket.mobflare.RpcCoordinator.java
String createFlare(String name, Bundle props) throws Exception { HttpPut httpPut = new HttpPut(generateFlareUri(name)); try {/*ww w. j a v a 2 s . c om*/ JSONObject jsonObj = new JSONObject(); for (String key : props.keySet()) { jsonObj.put(key, props.get(key)); } httpPut.setEntity(new StringEntity(jsonObj.toString())); HttpResponse httpResponse = execute(httpPut); if (httpResponse.getStatusLine().getStatusCode() == 409) { errId = R.string.duplicate_flare_name; throw new RuntimeException("Flare name already in use"); } String json = readInputStream(httpResponse.getEntity().getContent()); JSONTokener tokener = new JSONTokener(json); jsonObj = new JSONObject(tokener); return jsonObj.getString("name"); } catch (Exception ex) { Log.e(LOGTAG, "HTTP PUT failed", ex); throw ex; } }
From source file:com.annuletconsulting.homecommand.node.MainFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getActivity()); speechRecognizer.setRecognitionListener(new RecognitionListener() { @Override/*w ww . j a v a 2 s . c o m*/ public void onReadyForSpeech(Bundle params) { for (String key : params.keySet()) Log.d(TAG, (String) params.get(key)); } @Override public void onBeginningOfSpeech() { Log.d(TAG, "Begin"); ignore = false; } @Override public void onRmsChanged(float rmsdB) { // Log.d(TAG, "Rms changed: "+rmsdB); } @Override public void onBufferReceived(byte[] buffer) { Log.d(TAG, "Buffer Received: " + buffer.toString()); } @Override public void onEndOfSpeech() { Log.d(TAG, "Endofspeech()"); } @Override public void onError(int error) { Log.d(TAG, "error: " + error); } @Override public void onResults(Bundle results) { Log.d(TAG, "onResults()"); for (String key : results.keySet()) { Log.d(TAG, key + ": " + results.get(key).toString()); // Iterator<String> it = ((ArrayList<String>) // results.get(key)).listIterator(); // while (it.hasNext()) // Log.d(TAG, it.next()); } if (!ignore) sendToServer(results.getStringArrayList(RESULTS_KEY).get(0)); } @Override public void onPartialResults(Bundle partialResults) { // Log.d(TAG, "onPartialResults()"); // String firstWord = partialResults.getStringArrayList(RESULTS_KEY).get(0).split(" ")[0]; // Log.d(TAG, firstWord); // if (firstWord.length() > 0 && !firstWord.equalsIgnoreCase("computer") && !firstWord.equalsIgnoreCase("android")) { // Log.d(TAG, "Killing this Recognition."); // ignore = true; // stopRecognizing(); // startListening(); // } } @Override public void onEvent(int eventType, Bundle params) { Log.d(TAG, "onEvent() type: " + eventType); for (String key : params.keySet()) Log.d(TAG, (String) params.get(key)); } }); View v = inflater.inflate(R.layout.main_fragment, null); button = (Button) v.findViewById(R.id.listen_button); button.setBackgroundResource(R.drawable.stopped); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { toggleListenMode(); } }); instance = this; return v; }
From source file:com.example.hllut.app.Deprecated.MainActivity.java
/** * Parse the data received from the intent. Assign the total CO2 output to a * local variable and fill a local HashMap with the food categories and their CO2 output. *///ww w. j av a2 s . c o m private void parse(Bundle data) { String[] foodTypes = data.keySet().toArray(new String[data.size()]); for (String s : foodTypes) { if (s.matches("Total")) { total = data.getFloat(s); } else { float cO2 = data.getFloat(s); food.put(s, cO2); } } System.out.println(food); }
From source file:com.google.android.gcm.demo.logic.DeviceGroupsHelper.java
private List<String> bundleValues2Array(Bundle bundle) { ArrayList<String> values = new ArrayList<>(); for (String key : bundle.keySet()) { values.add(bundle.getString(key)); }/* w w w .j av a2 s . co m*/ return values; }