List of usage examples for android.content Intent getStringExtra
public String getStringExtra(String name)
From source file:com.example.android.sunshine.service.SunshineService.java
@Override protected void onHandleIntent(Intent intent) { String locationQuery = intent.getStringExtra(LOCATION_QUERY_EXTRA); // These two need to be declared outside the try/catch // so that they can be closed in the finally block. HttpURLConnection urlConnection = null; BufferedReader reader = null; // Will contain the raw JSON response as a string. String forecastJsonStr = null; String format = "json"; String units = "metric"; int numDays = 14; try {/*from ww w.ja v a 2 s . c om*/ // Construct the URL for the OpenWeatherMap query // Possible parameters are avaiable at OWM's forecast API page, at // http://openweathermap.org/API#forecast final String FORECAST_BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily?"; final String QUERY_PARAM = "q"; final String FORMAT_PARAM = "mode"; final String UNITS_PARAM = "units"; final String DAYS_PARAM = "cnt"; Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon().appendQueryParameter(QUERY_PARAM, locationQuery) .appendQueryParameter(FORMAT_PARAM, format).appendQueryParameter(UNITS_PARAM, units) .appendQueryParameter(DAYS_PARAM, Integer.toString(numDays)).build(); URL url = new URL(builtUri.toString()); // Create the request to OpenWeatherMap, and open the connection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); // Read the input stream into a String InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { // Nothing to do. return; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { // Since it's JSON, adding a newline isn't necessary (it won't affect parsing) // But it does make debugging a *lot* easier if you print out the completed // buffer for debugging. buffer.append(line + "\n"); } if (buffer.length() == 0) { // Stream was empty. No point in parsing. return; } forecastJsonStr = buffer.toString(); getWeatherDataFromJson(forecastJsonStr, locationQuery); } catch (IOException e) { Log.e(LOG_TAG, "Error ", e); // If the code didn't successfully get the weather data, there's no point in attempting // to parse it. } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } finally { if (urlConnection != null) { urlConnection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { Log.e(LOG_TAG, "Error closing stream", e); } } } return; }
From source file:com.example.qrpoll.PollActivity.java
@Override /**/* w w w. j a v a 2s . c o m*/ * ustawienie wygladu okna, przypisanie akcji do gwiazdek */ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_poll); expListView = (ExpandableListView) findViewById(R.id.lvExp); tv1 = (TextView) findViewById(R.id.textView1); tv2 = (TextView) findViewById(R.id.textView2); tv3 = (TextView) findViewById(R.id.textView3); tv4 = (TextView) findViewById(R.id.textView4); version = (TextView) findViewById(R.id.poll_textViewVersionLabel); rb = (RatingBar) findViewById(R.id.ratingBar1); rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener() { public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { int rate = (int) (2 * rating); AboutDevice sr = new AboutDevice(getApplicationContext()); if (version.getText().equals("1")) { switch (rate) { case 0: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(10)); break; case 1: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(9)); break; case 2: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(8)); break; case 3: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(7)); break; case 4: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(6)); break; case 5: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(5)); break; case 6: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(4)); break; case 7: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(3)); break; case 8: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(2)); break; case 9: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(1)); break; case 10: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(0)); break; } } else { switch (rate) { case 0: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(0)); break; case 1: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(1)); break; case 2: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(2)); break; case 3: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(3)); break; case 4: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(4)); break; case 5: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(5)); break; case 6: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(6)); break; case 7: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(7)); break; case 8: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(8)); break; case 9: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(9)); break; case 10: poll.vote(sr.createIdToSend() + "/" + poll.ratingquestions.get(10)); break; } } } }); Intent intent = getIntent(); String url = intent.getStringExtra("scanResult"); url = "http://" + url; getPoll(url); try { prepareListData(); listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild, poll); expListView.setAdapter(listAdapter); Refresh refresh = (Refresh) new Refresh(poll, this).execute(); String message = intent.getStringExtra("message"); if (!message.equals("none")) { Toast.makeText(getApplicationContext(), "Zaktualizowano pytania. Aktualna wersja: " + poll.getVersion(), Toast.LENGTH_LONG).show(); } } catch (Exception e) { Intent it = new Intent(getApplication(), MainActivity.class); startActivity(it); finish(); } }
From source file:com.example.android.sunshine.app.service.SunshineService.java
@Override protected void onHandleIntent(Intent intent) { String locationQuery = intent.getStringExtra(LOCATION_QUERY_EXTRA); // These two need to be declared outside the try/catch // so that they can be closed in the finally block. HttpURLConnection urlConnection = null; BufferedReader reader = null; // Will contain the raw JSON response as a string. String forecastJsonStr = null; String format = "json"; String units = "metric"; int numDays = 14; try {/* w ww .jav a 2 s . c o m*/ // Construct the URL for the OpenWeatherMap query // Possible parameters are avaiable at OWM's forecast API page, at // http://openweathermap.org/API#forecast final String FORECAST_BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily?"; final String QUERY_PARAM = "q"; final String FORMAT_PARAM = "mode"; final String UNITS_PARAM = "units"; final String DAYS_PARAM = "cnt"; final String APPID_PARAM = "APPID"; Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon().appendQueryParameter(QUERY_PARAM, locationQuery) .appendQueryParameter(FORMAT_PARAM, format).appendQueryParameter(UNITS_PARAM, units) .appendQueryParameter(DAYS_PARAM, Integer.toString(numDays)) .appendQueryParameter(APPID_PARAM, BuildConfig.OPEN_WEATHER_MAP_API_KEY).build(); URL url = new URL(builtUri.toString()); // Create the request to OpenWeatherMap, and open the connection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); // Read the input stream into a String InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { // Nothing to do. return; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { // Since it's JSON, adding a newline isn't necessary (it won't affect parsing) // But it does make debugging a *lot* easier if you print out the completed // buffer for debugging. buffer.append(line + "\n"); } if (buffer.length() == 0) { // Stream was empty. No point in parsing. return; } forecastJsonStr = buffer.toString(); getWeatherDataFromJson(forecastJsonStr, locationQuery); } catch (IOException e) { Log.e(LOG_TAG, "Error ", e); // If the code didn't successfully get the weather data, there's no point in attempting // to parse it. } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } finally { if (urlConnection != null) { urlConnection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { Log.e(LOG_TAG, "Error closing stream", e); } } } return; }
From source file:com.mytalentfolio.h_daforum.CPreviousBatchForum.java
/** * Gets the intent data.// w ww . j a va2 s .c om * * @return the intent data */ private void getIntentData() { Intent i = getIntent(); courseID = i.getStringExtra("courseID"); userID = i.getStringExtra("userID"); currentCourse = i.getStringExtra("currentcourseID"); //getDataFromServer(courseID); }
From source file:com.github.sgelb.booket.SearchResultActivity.java
private String createUrl() { Intent intent = getIntent(); String author = intent.getStringExtra(BookSearchActivity.AUTHOR); String title = intent.getStringExtra(BookSearchActivity.TITLE); String isbn = intent.getStringExtra(BookSearchActivity.ISBN); String keyword = intent.getStringExtra(BookSearchActivity.KEYWORD); String language = intent.getStringExtra(BookSearchActivity.LANGUAGE); String query = ""; try {//from ww w . j a v a2 s. c o m if (!isbn.isEmpty()) { query += "+isbn:" + URLEncoder.encode(isbn, "utf-8"); } else { if (!author.isEmpty()) query += "+inauthor:" + URLEncoder.encode(author, "utf-8"); if (!title.isEmpty()) query += "+intitle:" + URLEncoder.encode(title, "utf-8"); if (!keyword.isEmpty()) query += URLEncoder.encode(keyword, "utf-8"); if (!language.isEmpty()) query += "&langRestrict=" + URLEncoder.encode(language, "utf-8"); } } catch (UnsupportedEncodingException e) { } query += "&fields=items(volumeInfo,id)&maxResults=40"; Log.d("R2R", "URL: " + query); return "https://www.googleapis.com/books/v1/volumes?q=" + query; }
From source file:net.olejon.spotcommander.PlaylistsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Allow landscape? if (!mTools.allowLandscape()) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); // Intent/*w w w . j a v a 2s . co m*/ final Intent intent = getIntent(); // Computer final long computerId = mTools.getSharedPreferencesLong( "WIDGET_" + intent.getStringExtra(WidgetLarge.WIDGET_LARGE_INTENT_EXTRA) + "_COMPUTER_ID"); final String[] computer = mTools.getComputer(computerId); // Layout setContentView(R.layout.activity_playlists); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.playlists_toolbar); toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp); toolbar.setTitle(getString(R.string.playlists_title)); setSupportActionBar(toolbar); // Progress bar mProgressBar = (ProgressBar) findViewById(R.id.playlists_progressbar); mProgressBar.setVisibility(View.VISIBLE); // Listview mListView = (ListView) findViewById(R.id.playlists_list); // Get playlists final Cache cache = new DiskBasedCache(getCacheDir(), 0); final Network network = new BasicNetwork(new HurlStack()); final RequestQueue requestQueue = new RequestQueue(cache, network); requestQueue.start(); final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, computer[0] + "/playlists.php?get_playlists_as_json", null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { requestQueue.stop(); try { final ArrayList<String> playlistNames = new ArrayList<>(); final Iterator<?> iterator = response.keys(); while (iterator.hasNext()) { String key = (String) iterator.next(); playlistNames.add(key); } Collections.sort(playlistNames, new Comparator<String>() { @Override public int compare(String string1, String string2) { return string1.compareToIgnoreCase(string2); } }); for (String playlistName : playlistNames) { mPlaylistUris.add(response.getString(playlistName)); } final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(mContext, R.layout.activity_playlists_list_item, playlistNames); mProgressBar.setVisibility(View.GONE); mListView.setAdapter(arrayAdapter); mListView.setVisibility(View.VISIBLE); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mTools.remoteControl(computerId, "shuffle_play_uri", mPlaylistUris.get(position)); finish(); } }); } catch (Exception e) { mProgressBar.setVisibility(View.GONE); final TextView textView = (TextView) findViewById(R.id.playlists_error); textView.setVisibility(View.VISIBLE); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { requestQueue.stop(); mProgressBar.setVisibility(View.GONE); final TextView textView = (TextView) findViewById(R.id.playlists_error); textView.setVisibility(View.VISIBLE); } }) { @Override public HashMap<String, String> getHeaders() { final HashMap<String, String> hashMap = new HashMap<>(); if (!computer[1].equals("") && !computer[2].equals("")) hashMap.put("Authorization", "Basic " + Base64.encodeToString((computer[1] + ":" + computer[2]).getBytes(), Base64.NO_WRAP)); return hashMap; } }; jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(2500, 0, 0)); requestQueue.add(jsonObjectRequest); }
From source file:com.hybris.mobile.activity.PaymentDetailActivity.java
@SuppressWarnings("unchecked") private void handleIntent(Intent intent) { if (intent.hasExtra("value")) { try {/*from w w w.ja va 2 s . c om*/ JSONObject payment = new JSONObject(intent.getStringExtra("value")); mPaymentID = payment.getString("id"); for (int i = 0; i < entries.size(); i++) { Hashtable<String, Object> dict = (Hashtable<String, Object>) entries.get(i); String path = "$." + dict.get("property").toString(); String value = ""; try { // We append a String a the end to handle the non String objects value = JsonPath.read(payment.toString(), path) + ""; } catch (Exception exp) { value = ""; } if (value != null) { dict.put("value", value); } } } catch (JSONException e) { LoggingUtils.e(LOG_TAG, "Error parsing Json. " + e.getLocalizedMessage(), Hybris.getAppContext()); } } }
From source file:com.makotosan.vimeodroid.TransferService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { counter++;//from ww w. j av a 2s . co m transfer = new Transfer(); final String videoUri = intent.getStringExtra("videouri"); final TransferType transferType = TransferType.valueOf(intent.getStringExtra("transferType")); final String fileName = intent.getStringExtra("fileName"); Bitmap bitmapThumbnail = null; int transferIcon = android.R.drawable.stat_sys_download; if (transferType == TransferType.Upload) { // Get the resource ID for the video final long resourceId = ContentUris.parseId(Uri.parse(videoUri)); bitmapThumbnail = android.provider.MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(), resourceId, android.provider.MediaStore.Video.Thumbnails.MICRO_KIND, null); transfer.setIcon(bitmapThumbnail); transferIcon = android.R.drawable.stat_sys_upload; } // Initialize our notification final Notification notification = new Notification(transferIcon, "Transferring...", System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; notification.contentView = new RemoteViews(this.getPackageName(), R.layout.transferprogress); final Intent manageIntent = new Intent(this, ManageTransfersActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, manageIntent, 0); notification.contentIntent = pendingIntent; if (bitmapThumbnail != null) { notification.contentView.setImageViewBitmap(R.id.transferprogressIcon, bitmapThumbnail); } else { notification.contentView.setImageViewResource(R.id.transferprogressIcon, R.drawable.icon); } notification.contentView.setProgressBar(R.id.transferprogressBar, 100, 0, false); notification.contentView.setTextViewText(R.id.transferprogressText, "Transferring... "); notification.contentView.setOnClickPendingIntent(R.layout.transferprogress, pendingIntent); // Add it to the collection of notifications notifications.put(counter, notification); // Add our notification to the notification tray notificationManager.notify(counter, notification); // Initialize our asynchronous transfer task final TransferTask task = new TransferTask(counter, transferType); task.execute(videoUri, fileName); return Service.START_STICKY; }
From source file:com.nokia.example.paymentoneapk.PaymentOneAPKActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); String purchaseDataJson = data.getStringExtra("INAPP_PURCHASE_DATA"); Log.d(TAG, "PaymentOneAPKActivity.onActivityResult"); Log.d(TAG, String.format("requestCode = %d", requestCode)); Log.d(TAG, String.format("resultCode = %d", resultCode)); Log.d(TAG, "purchaseDataJson = " + purchaseDataJson); if (resultCode == RESULT_OK) { toastMessage("Item purchased"); } else {/* ww w . j a va2 s.c o m*/ toastMessage("Error while purchasing product"); } String token = ""; try { JSONObject purchaseData = new JSONObject(purchaseDataJson); token = purchaseData.getString("purchaseToken"); } catch (JSONException e) { Log.e(TAG, "error while parsing JSON", e); toastMessage("Error while parsing JSON"); return; } consumeTestProduct(token); }
From source file:it.iziozi.iziozi.gui.IORemoteImageSearchActivity.java
private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); searchImages(query);// ww w.j a v a 2 s . c o m } }