List of usage examples for android.os Bundle get
@Nullable
public Object get(String key)
From source file:com.javathlon.MyGcmListenerService.java
/** * Called when message is received.//from ww w .ja v a 2s . c o m * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String title = (String) ((Bundle) data.get("notification")).get("title"); String message = (String) ((Bundle) data.get("notification")).get("message"); String type = (String) ((Bundle) data.get("notification")).get("actionType"); if (type == null) type = "podcast"; String url = (String) ((Bundle) data.get("notification")).get("targetUrl"); Log.d(TAG, "From: " + from); Log.d(TAG, "Message: " + message); if (from.startsWith("/topics/")) { // message received from some topic. Log.d("dasdsa", message); } else { Log.d("dasdsa", message); // normal downstream message. } // [START_EXCLUDE] /** * Production applications would usually process the message here. * Eg: - Syncing with server. * - Store message in local database. * - Update UI. */ /** * In some cases it may be useful to show a notification indicating to the user * that a message was received. */ sendNotification(title, message, type, url); // [END_EXCLUDE] }
From source file:com.gmail.at.faint545.services.DataQueueService.java
@Override protected void onHandleIntent(Intent intent) { String url = intent.getStringExtra("url"); String api = intent.getStringExtra("api"); StringBuilder results = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(url); ArrayList<NameValuePair> arguments = new ArrayList<NameValuePair>(); arguments.add(new BasicNameValuePair(SabnzbdConstants.APIKEY, api)); arguments.add(new BasicNameValuePair(SabnzbdConstants.OUTPUT, SabnzbdConstants.OUTPUT_JSON)); arguments.add(new BasicNameValuePair(SabnzbdConstants.MODE, SabnzbdConstants.MODE_QUEUE)); try {/* ww w . j a v a 2 s.c o m*/ request.setEntity(new UrlEncodedFormEntity(arguments)); HttpResponse result = client.execute(request); InputStream inStream = result.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(inStream), 8); String line; while ((line = br.readLine()) != null) { if (line.length() > 0) { results.append(line); } } br.close(); inStream.close(); Bundle extras = intent.getExtras(); Messenger messenger = (Messenger) extras.get("messenger"); Message message = Message.obtain(); Bundle resultsBundle = new Bundle(); resultsBundle.putString("results", results.toString()); message.setData(resultsBundle); messenger.send(message); stopSelf(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } }
From source file:com.bukanir.android.activities.MovieActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate"); super.onCreate(savedInstanceState); supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_movie); fragmentManager = getSupportFragmentManager(); final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); if (savedInstanceState != null) { movie = (Movie) savedInstanceState.getSerializable("movie"); } else {//from w w w . j a v a 2 s . com Bundle bundle = getIntent().getExtras(); movie = (Movie) bundle.get("movie"); movieTask = new MovieTask(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { movieTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { movieTask.execute(); } } }
From source file:karroo.app.test.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 ww w . ja v a 2s.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; 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) { 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:in.trycatchthrow.trouvaille.MyGcmListenerService.java
/** * Called when message is received./*from www . j a va2s . c o m*/ * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); Object notice = (Object) data.get("Notice"); Log.d(TAG, "From: " + from); Log.d(TAG, "Message: " + message); if (from.startsWith("/topics/")) { // message received from some topic. } else { // normal downstream message. } // [START_EXCLUDE] /** * Production applications would usually process the message here. * Eg: - Syncing with server. * - Store message in local database. * - Update UI. */ /** * In some cases it may be useful to show a notification indicating to the user * that a message was received. */ sendNotification(message); // [END_EXCLUDE] }
From source file:com.commonsware.android.tuning.downloader.Downloader.java
@Override public void onHandleIntent(Intent i) { HttpGet getMethod = new HttpGet(i.getData().toString()); int result = Activity.RESULT_CANCELED; try {// w ww . j ava2 s . c o m ResponseHandler<byte[]> responseHandler = new ByteArrayResponseHandler(); byte[] responseBody = client.execute(getMethod, responseHandler); File output = new File(Environment.getExternalStorageDirectory(), i.getData().getLastPathSegment()); if (output.exists()) { output.delete(); } FileOutputStream fos = new FileOutputStream(output.getPath()); fos.write(responseBody); fos.close(); result = Activity.RESULT_OK; } catch (IOException e2) { Log.e(getClass().getName(), "Exception in download", e2); } Bundle extras = i.getExtras(); if (extras != null) { Messenger messenger = (Messenger) extras.get(EXTRA_MESSENGER); Message msg = Message.obtain(); msg.arg1 = result; try { messenger.send(msg); } catch (android.os.RemoteException e1) { Log.w(getClass().getName(), "Exception sending message", e1); } } }
From source file:fr.julienvermet.bugdroid.service.ProductsIntentService.java
private void sendResult(Intent intent, ArrayList<Product> products) { Bundle extras = intent.getExtras(); Messenger messenger = (Messenger) extras.get(MESSENGER); if (messenger != null) { Message msg = Message.obtain();//from w w w . ja v a 2 s. c o m Bundle data = new Bundle(); data.putSerializable(PRODUCTS, products); msg.setData(data); try { messenger.send(msg); } catch (android.os.RemoteException e1) { Log.w(getClass().getName(), "Exception sending message", e1); } } }
From source file:io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.java
/** @return true if intent contained a message to send. */ private boolean sendMessageFromIntent(String method, Intent intent) { if (CLICK_ACTION_VALUE.equals(intent.getAction()) || CLICK_ACTION_VALUE.equals(intent.getStringExtra("click_action"))) { Map<String, String> message = new HashMap<>(); Bundle extras = intent.getExtras(); for (String key : extras.keySet()) { message.put(key, extras.get(key).toString()); }/* w w w . ja v a2 s . c o m*/ channel.invokeMethod(method, message); return true; } return false; }
From source file:butter.droid.base.fragments.dialog.StringArraySelectorDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (getArguments() == null || !getArguments().containsKey(ARRAY) || !getArguments().containsKey(TITLE) || mOnClickListener == null) { return builder.create(); }/*from w ww .j av a2s .c o m*/ Bundle b = getArguments(); Object array = b.get(ARRAY); String[] stringArray; if (array instanceof List) { stringArray = (String[]) ((List) array).toArray(new String[((List) array).size()]); } else if (array instanceof String[]) { stringArray = b.getStringArray(ARRAY); } else { return builder.create(); } String title = b.getString(TITLE); if (b.containsKey(MODE) && b.getInt(MODE) == SINGLE_CHOICE) { int defaultPosition = -1; if (b.containsKey(POSITION)) { defaultPosition = b.getInt(POSITION); } builder.setSingleChoiceItems(stringArray, defaultPosition, mOnClickListener); } else { builder.setItems(stringArray, mOnClickListener); } builder.setTitle(title).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); return builder.create(); }
From source file:com.google.android.apps.chrometophone.GCMIntentService.java
@Override public void onMessage(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { String url = (String) extras.get("url"); String title = (String) extras.get("title"); String sel = (String) extras.get("sel"); String debug = (String) extras.get("debug"); if (debug != null) { // server-controlled debug - the server wants to know // we received the message, and when. This is not user-controllable, // we don't want extra traffic on the server or phone. Server may // turn this on for a small percentage of requests or for users // who report issues. DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(AppEngineClient.BASE_URL + "/debug?id=" + extras.get("collapse_key")); // No auth - the purpose is only to generate a log/confirm delivery // (to avoid overhead of getting the token) try { client.execute(get);/*www . j ava2 s. c o m*/ } catch (ClientProtocolException e) { // ignore } catch (IOException e) { // ignore } } if (title != null && url != null && url.startsWith("http")) { SharedPreferences settings = Prefs.get(context); Intent launchIntent = LauncherUtils.getLaunchIntent(context, title, url, sel); // Notify and optionally start activity if (settings.getBoolean("launchBrowserOrMaps", true) && launchIntent != null) { LauncherUtils.playNotificationSound(context); LauncherUtils.sendIntentToApp(context, launchIntent); } else { LauncherUtils.generateNotification(context, url, title, launchIntent); } // Record history (for link/maps only) if (launchIntent != null && launchIntent.getAction().equals(Intent.ACTION_VIEW)) { HistoryDatabase.get(context).insertHistory(title, url); } } } }