List of usage examples for android.content Intent putExtras
public @NonNull Intent putExtras(@NonNull Bundle extras)
From source file:org.peterbaldwin.client.android.tinyurl.SendTinyUrlActivity.java
private void send() { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); Intent originalIntent = getIntent(); if (Intent.ACTION_SEND.equals(originalIntent.getAction())) { // Copy extras from the original intent because they might contain // additional information about the URL (e.g., the title of a // YouTube video). Do this before setting Intent.EXTRA_TEXT to avoid // overwriting the TinyURL. intent.putExtras(originalIntent.getExtras()); }/*from w w w . j a v a2s . c o m*/ intent.putExtra(Intent.EXTRA_TEXT, mTinyUrl); try { CharSequence template = getText(R.string.title_send); String title = String.format(String.valueOf(template), mTinyUrl); startActivity(Intent.createChooser(intent, title)); finish(); } catch (ActivityNotFoundException e) { handleError(e); } }
From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java
@Override public void onReceive(Context context, Intent intent) { final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); // Get user preferences final SharedPreferences sharedPrefs = context.getSharedPreferences(Const.APP_PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences.Editor sharedPrefsEditor = sharedPrefs.edit(); final boolean hasNotifications = sharedPrefs.getBoolean(Const.PrefsNames.HAS_NOTIFICATIONS, false); final boolean hasVibration = (sharedPrefs.getBoolean(Const.PrefsNames.HAS_VIBRATION, false) && vibrator.hasVibrator()); final boolean hasSound = sharedPrefs.getBoolean(Const.PrefsNames.HAS_SOUND, false); final boolean onScreenLock = sharedPrefs.getBoolean(Const.PrefsNames.ON_SCREEN_LOCK, true); final boolean onPowerLoss = sharedPrefs.getBoolean(Const.PrefsNames.ON_POWER_LOSS, false); final int delayToLock = Integer.parseInt( sharedPrefs.getString(Const.PrefsNames.DELAY_TO_LOCK, Const.PrefsValues.DELAY_FAST)) * 1000; final int notifyCount = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_COUNT, 1); final int notifyGroup = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_GROUP, 1); final String action = intent.getAction(); if (action == null) return;//ww w . j a va2 s . c o m if (action.equals(Const.IntentActions.NOTIFY_DELETE)) { if (hasNotifications) { // Reset the notification counter (and group) on NOTIFY_DELETE sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, 1); sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_GROUP, notifyGroup + 1); sharedPrefsEditor.apply(); } } else if (action.equals(Intent.ACTION_POWER_CONNECTED) || action.equals(Intent.ACTION_POWER_DISCONNECTED)) { final boolean isConnectedPower = action.equals(Intent.ACTION_POWER_CONNECTED); // Lock the screen, following the user preferences if (delayToLock == 0) { LockScreenHelper.lockScreen(context, onScreenLock, onPowerLoss, isConnectedPower); } else { Intent intentService = new Intent(Intent.ACTION_SYNC, null, context, DelayedLockService.class); Bundle extras = new Bundle(); extras.putBoolean(Const.IntentExtras.ON_SCREEN_LOCK, onScreenLock); extras.putBoolean(Const.IntentExtras.ON_POWER_LOSS, onPowerLoss); extras.putBoolean(Const.IntentExtras.IS_CONNECTED, isConnectedPower); extras.putInt(Const.IntentExtras.DELAY_TO_LOCK, delayToLock); intentService.putExtras(extras); context.startService(intentService); } // Save in database saveHistoryItem(context.getApplicationContext(), isConnectedPower, notifyGroup); if (hasNotifications) { // Send notification, with sound and vibration notify(context, isConnectedPower, hasVibration, hasSound, notifyCount); // Increment the notification counter sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, notifyCount + 1); sharedPrefsEditor.apply(); } else { // Native Vibration or Sound, without Notifications nativeVibrate(context, hasVibration); nativeRingtone(context, hasSound); } } }
From source file:com.andryr.musicplayer.activities.SearchActivity.java
private void returnToMain(String action, Bundle data) { Intent i = new Intent(action); if (data != null) { i.putExtras(data); }//from ww w .j a v a 2 s .com setResult(RESULT_OK, i); finish(); }
From source file:org.mrquiz.android.tinyurl.SendTinyUrlActivity.java
private void send() { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); Intent originalIntent = getIntent(); if (Intent.ACTION_SEND.equals(originalIntent.getAction())) { // Copy extras from the original intent because they miht contain // additional information about the URL (e.g., the title of a // YouTube video). Do this before setting Intent.EXTRA_TEXT to avoid // overwriting the TinyShare. intent.putExtras(originalIntent.getExtras()); }/*from ww w. j a v a2 s. c om*/ intent.putExtra(Intent.EXTRA_TEXT, mTinyUrl); try { CharSequence template = getText(R.string.title_send); String title = String.format(String.valueOf(template), mTinyUrl); startActivity(Intent.createChooser(intent, title)); } catch (ActivityNotFoundException e) { handleError(e); } }
From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Home.CarBrowse.java
public void getCars(final Location location) { final String url = API.carsNearby + "/" + location.getLatitude() + "/" + location.getLongitude(); try {//from w w w .ja v a 2 s . c om final API.doRequest task = new API.doRequest(new API.doRequest.TaskListener() { @Override public void postExecute(JSONArray result) throws JSONException { JSONObject serverResponse = result.getJSONObject(result.length() - 1); int statusCode = serverResponse.getInt("statusCode"); result.remove(result.length() - 1); final FragmentActivity activity = getActivity(); if (activity == null) { return; } final ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar(); if (statusCode == 200) { final View view = getView(); if (view == null) { return; } final ListView listView = (ListView) view.findViewById(R.id.listView); final ArrayList<CarData> carsArray = new ArrayList<CarData>(); for (int i = 0; i < result.length(); i++) { final CarData tempCarData = new CarData(result.getJSONObject(i)); carsArray.add(tempCarData); final LatLng carLocation = new LatLng(tempCarData.lat, tempCarData.lng); mMap.addMarker(new MarkerOptions().position(carLocation).title(tempCarData.title) .icon(BitmapDescriptorFactory.fromResource(R.drawable.models))); } Collections.sort(carsArray, new Comparator<CarData>() { @Override public int compare(CarData lhs, CarData rhs) { return lhs.distance - rhs.distance; } }); final CarDataAdapter adapter = new CarDataAdapter(activity.getApplicationContext(), carsArray); listView.setAdapter(adapter); final ArrayList<CarData> finalCarsArray = carsArray; listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) { final Intent carDetails = new Intent(view.getContext(), CarDetails.class); final Bundle bundle = new Bundle(); bundle.putSerializable("carData", finalCarsArray.get(position)); carDetails.putExtras(bundle); startActivity(carDetails); } }); if (carsArray.size() == 0) { final Toast toast = Toast.makeText(activity.getApplicationContext(), "No car available in this area. Location information may be incorrect. Make sure GPS or Wifi is effective and try again. Or, Free Plan limitation, ask administrator to delete registered cars.", Toast.LENGTH_LONG); toast.show(); supportActionBar.setTitle("No car available."); } else { final String title = (carsArray.size() == 1) ? "1 car found." : carsArray.size() + " cars found."; supportActionBar.setTitle(title); } Log.i("Car Data", result.toString()); } else if (statusCode == 500) { final Toast toast = Toast.makeText(activity.getApplicationContext(), "A server internal error received. Ask your administrator.", Toast.LENGTH_LONG); toast.show(); supportActionBar.setTitle("Error: Server internal error."); } else { final Toast toast = Toast.makeText(activity.getApplicationContext(), "Error: Unable to connect to server.", Toast.LENGTH_LONG); toast.show(); supportActionBar.setTitle("Error: Not connected to server."); } } }); task.execute(url, "GET").get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } }
From source file:com.dzt.uberclone.HomeFragment.java
private void handleDriverTracking(String json) { try {// w w w . j ava 2 s .c o m JSONObject jsonObject = new JSONObject(json); if (jsonObject.has("fee")) { trackDriverBoolean = false; double initialLat = jsonObject.getDouble("initial_lat"); double initialLng = jsonObject.getDouble("initial_lng"); double finalLat = jsonObject.getDouble("final_lat"); double finalLng = jsonObject.getDouble("final_lng"); String distance = jsonObject.getString("distance"); String time = jsonObject.getString("time"); String fee = jsonObject.getString("fee"); String finalFee = jsonObject.getString("final_fee"); Bundle params = new Bundle(); params.putString("originText", initialLat + "," + initialLng); params.putString("destinationText", finalLat + "," + finalLng); params.putString("timeText", time); params.putString("distanceText", distance); params.putString("feeText", fee); params.putString("finalFeeText", finalFee); params.putString("rideId", currentRideId); /* StringBuilder sb = new StringBuilder(); sb.append("You went from "); sb.append(initialLat); sb.append(","); sb.append(initialLng); sb.append(" to "); sb.append(finalLat); sb.append(","); sb.append(finalLng); sb.append(". Your time was "); sb.append(time); sb.append(" minutes and rode a distance of "); sb.append(distance); sb.append(" KM. Your fee is $"); sb.append(fee); sb.append(" and your adjusted fee is $"); sb.append(finalFee); Log.i("ride details", sb.toString()); Toast.makeText(getActivity(), sb.toString(), Toast.LENGTH_LONG).show(); */ Intent intent = new Intent(getActivity(), RideDetailsActivity.class); intent.putExtras(params); startActivity(intent); getActivity().finish(); } else { double lat = jsonObject.getDouble("latitude"); double lng = jsonObject.getDouble("longitude"); addAssignedUberMarker(lat, lng); } } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.first3.viz.download.DownloadManager.java
/** * Show a notification while this service is running. *///from www .ja va2s .co m private void showNotification(boolean setTicker) { int numDownloads = numOngoingDownloads(); int numQueued = downloadQueue.size(); String videos = getResources().getQuantityString(R.plurals.notification_title_numvideos, numDownloads, numDownloads); String queued = getResources().getQuantityString(R.plurals.notification_subtitle_numqueued, numQueued, numQueued); Intent startViz = new Intent(this, ActivityDelegate.class); Bundle bundle = new Bundle(); bundle.putInt(ActivityDelegate.BUNDLE_LOAD_TAB, 3); // navigate to the Downloads tab startViz.putExtras(bundle); PendingIntent intent = PendingIntent.getActivity(this, 0, startViz, 0); Bitmap notificationIconLarge = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); String tickerText; if (numQueued > 0) { tickerText = videos + ", " + queued; } else { tickerText = videos; } NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setLargeIcon(notificationIconLarge).setSmallIcon(R.drawable.ic_stat_notification_arrow) .setContentTitle(videos).setContentIntent(intent); if (setTicker) { builder.setTicker(tickerText); } if (numQueued > 0) { builder.setContentText(queued); } Notification notification = builder.getNotification(); // need to update support lib startForeground(VIZ_NOTIFICATION, notification); mNM.notify(VIZ_NOTIFICATION, notification); }
From source file:com.forum.fiend.osp.SettingsFragment.java
private void launchUsersList() { SharedPreferences app_preferences = getActivity().getSharedPreferences("prefs", 0); String accent;/*from www. j a v a 2 s. co m*/ if (app_preferences.getString(storagePrefix + "logged_bgColor", getString(R.string.default_color)) .contains("#")) { accent = app_preferences.getString(storagePrefix + "logged_bgColor", getString(R.string.default_color)); } else { accent = getString(R.string.default_color); } Intent myIntent = new Intent(getActivity(), ActiveUsersActivity.class); Bundle bundle = new Bundle(); bundle.putString("background", (String) accent); myIntent.putExtras(bundle); startActivity(myIntent); }
From source file:com.odoo.addons.sale.SalesDetail.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.layoutAddItem: if (mForm.getValues() != null) { Intent intent = new Intent(this, AddProductLineWizard.class); Bundle extra = new Bundle(); for (String key : lineValues.keySet()) { extra.putFloat(key, lineValues.get(key)); }/*from ww w . j ava2 s .c o m*/ intent.putExtras(extra); startActivityForResult(intent, REQUEST_ADD_ITEMS); } break; } }
From source file:com.facebook.android.friendsmash.HomeFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REAUTH_ACTIVITY_CODE) { // This ensures a session state change is recorded so that the tokenUpdated() callback is triggered // to attempt a post if the write permissions have been granted Log.i(FriendSmashApplication.TAG, "Reauthorized with publish permissions."); Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data); } else if (resultCode == Activity.RESULT_OK && data != null) { // Finished a game Bundle bundle = data.getExtras(); application.setScore(bundle.getInt("score")); updateYouScoredTextView();// w ww . ja v a 2 s .c o m updateButtonVisibility(); completeGameOver(1500); } else if (resultCode == Activity.RESULT_FIRST_USER && data != null) { // Came from the ScoreboardFragment, so start a game with the specific user who has been clicked Intent i = new Intent(getActivity(), GameActivity.class); Bundle bundle = new Bundle(); bundle.putString("user_id", data.getStringExtra("user_id")); i.putExtras(bundle); startActivityForResult(i, 0); } else if (resultCode == Activity.RESULT_CANCELED && data != null) { Bundle bundle = data.getExtras(); ((HomeActivity) getActivity()).showError(bundle.getString("error"), false); } else if (resultCode == Activity.RESULT_CANCELED && ((FriendSmashApplication) getActivity().getApplication()) .getGameFragmentFBRequestError() != null) { ((HomeActivity) getActivity()).handleError( ((FriendSmashApplication) getActivity().getApplication()).getGameFragmentFBRequestError(), false); ((FriendSmashApplication) getActivity().getApplication()).setGameFragmentFBRequestError(null); } }