List of usage examples for android.content Intent addCategory
public @NonNull Intent addCategory(String category)
From source file:com.fbbackup.MyFriendFragmentActivity.java
/** * }app/*from w w w . j av a 2 s . c o m*/ */ public void exit() { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); }
From source file:org.universAAL.android.proxies.ServiceCalleeProxy.java
@Override public void handleRequest(BusMessage m) { ServiceCall call = (ServiceCall) m.getContent(); // Extract the origin action and category from the call String fromAction = (String) call.getNonSemanticInput(AppConstants.UAAL_META_PROP_FROMACTION); String fromCategory = (String) call.getNonSemanticInput(AppConstants.UAAL_META_PROP_FROMCATEGORY); Boolean needsOuts = (Boolean) call.getNonSemanticInput(AppConstants.UAAL_META_PROP_NEEDSOUTPUTS); boolean isNonIntrusive = fromAction != null && fromAction.equals(action) && fromCategory != null && fromCategory.equals(category); // This means the serv Intent in the caller proxy is the same as the // serv Intent in destination native app. Therefore the destination will // already have received it and we must not send the intent to avoid // duplication or infinite loops. if (!isNonIntrusive) { // In this case the serv intents are different because the origin // action+cat is being used as a kind of API to call the SCaller. // In this case we have to relay the call to the destination native app. Context ctxt = contextRef.get(); if (ctxt != null) { // Prepare an intent for sending to Android grounded service Intent serv = new Intent(action); serv.addCategory(category); boolean expecting = false; // If a response is expected, prepare a callback receiver (which must be called by uaalized app) if ((replyAction != null && !replyAction.isEmpty()) && (replyCategory != null && !replyCategory.isEmpty())) { // Tell the destination where to send the reply serv.putExtra(AppConstants.ACTION_META_REPLYTOACT, replyAction); serv.putExtra(AppConstants.ACTION_META_REPLYTOCAT, replyCategory); // Register the receiver for the reply receiver = new ServiceCalleeProxyReceiver(m);// TODO Can only handle 1 call at a time per proxy IntentFilter filter = new IntentFilter(replyAction); filter.addCategory(replyCategory); ctxt.registerReceiver(receiver, filter); expecting = true;// w w w. j ava2s . c o m } else if (needsOuts != null && needsOuts.booleanValue()) { // No reply* fields set, but caller still needs a response, // lets build one (does not work for callers outside android MW) Random r = new Random(); String action = AppConstants.ACTION_REPLY + r.nextInt(); serv.putExtra(AppConstants.ACTION_META_REPLYTOACT, action); serv.putExtra(AppConstants.ACTION_META_REPLYTOCAT, Intent.CATEGORY_DEFAULT); // Register the receiver for the reply receiver = new ServiceCalleeProxyReceiver(m); IntentFilter filter = new IntentFilter(action); filter.addCategory(Intent.CATEGORY_DEFAULT); ctxt.registerReceiver(receiver, filter); expecting = true; } // Take the inputs from the call and put them in the intent if (inputURItoExtraKEY != null && !inputURItoExtraKEY.isEmpty()) { VariableSubstitution.putCallInputsAsIntentExtras(call, serv, inputURItoExtraKEY); } // Flag to avoid feeding back the intent to bus when intent is the same in app and in callerproxy serv.putExtra(AppConstants.ACTION_META_FROMPROXY, true); // Send the intent to Android grounded service ComponentName started = ctxt.startService(serv);//Not allowed in Android 5.0 (fall back to broadcast) if (started == null) { // No android service was there, try with broadcast. Before, here it used to send failure response ctxt.sendBroadcast(serv); // No way to know if received. If no response, bus will timeout (?) } else if (!expecting) { // There is no receiver waiting a response, send success now ServiceResponse resp = new ServiceResponse(CallStatus.succeeded); sendResponse(m, resp); } //TODO Handle timeout } } }
From source file:com.farmerbb.notepad.fragment.NoteListFragment.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override// ww w . j a v a2 s .c om public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_start_selection: listener.startMultiSelect(); return true; case R.id.action_settings: Intent intentSettings = new Intent(getActivity(), SettingsActivity.class); startActivity(intentSettings); return true; case R.id.action_import: Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "text/plain", "text/html", "text/x-markdown" }); intent.setType("*/*"); try { getActivity().startActivityForResult(intent, MainActivity.IMPORT); } catch (ActivityNotFoundException e) { showToast(R.string.error_importing_notes); } return true; case R.id.action_about: DialogFragment aboutFragment = new AboutDialogFragment(); aboutFragment.show(getFragmentManager(), "about"); return true; default: return super.onOptionsItemSelected(item); } }
From source file:gov.wa.wsdot.android.wsdot.service.MountainPassesSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;//from w w w.ja v a 2 s . co m long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "mountain_passes" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); buildWeatherPhrases(); try { URL url = new URL(MOUNTAIN_PASS_URL); URLConnection urlConn = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream()); GZIPInputStream gzin = new GZIPInputStream(bis); InputStreamReader is = new InputStreamReader(gzin); BufferedReader in = new BufferedReader(is); String mDateUpdated = ""; String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("GetMountainPassConditionsResult"); JSONArray passConditions = result.getJSONArray("PassCondition"); String weatherCondition; Integer weather_image; Integer forecast_weather_image; List<ContentValues> passes = new ArrayList<ContentValues>(); int numConditions = passConditions.length(); for (int j = 0; j < numConditions; j++) { JSONObject pass = passConditions.getJSONObject(j); ContentValues passData = new ContentValues(); weatherCondition = pass.getString("WeatherCondition"); weather_image = getWeatherImage(weatherPhrases, weatherCondition); String tempDate = pass.getString("DateUpdated"); try { tempDate = tempDate.replace("[", ""); tempDate = tempDate.replace("]", ""); String[] a = tempDate.split(","); StringBuilder sb = new StringBuilder(); for (int m = 0; m < 5; m++) { sb.append(a[m]); sb.append(","); } tempDate = sb.toString().trim(); tempDate = tempDate.substring(0, tempDate.length() - 1); Date date = parseDateFormat.parse(tempDate); mDateUpdated = displayDateFormat.format(date); } catch (Exception e) { Log.e(DEBUG_TAG, "Error parsing date: " + tempDate, e); mDateUpdated = "N/A"; } JSONArray forecasts = pass.getJSONArray("Forecast"); JSONArray forecastItems = new JSONArray(); int numForecasts = forecasts.length(); for (int l = 0; l < numForecasts; l++) { JSONObject forecast = forecasts.getJSONObject(l); if (isNight(forecast.getString("Day"))) { forecast_weather_image = getWeatherImage(weatherPhrasesNight, forecast.getString("ForecastText")); } else { forecast_weather_image = getWeatherImage(weatherPhrases, forecast.getString("ForecastText")); } forecast.put("weather_icon", forecast_weather_image); if (l == 0) { if (weatherCondition.equals("")) { weatherCondition = forecast.getString("ForecastText").split("\\.")[0] + "."; weather_image = forecast_weather_image; } } forecastItems.put(forecast); } passData.put(MountainPasses.MOUNTAIN_PASS_ID, pass.getString("MountainPassId")); passData.put(MountainPasses.MOUNTAIN_PASS_NAME, pass.getString("MountainPassName")); passData.put(MountainPasses.MOUNTAIN_PASS_WEATHER_ICON, weather_image); passData.put(MountainPasses.MOUNTAIN_PASS_FORECAST, forecastItems.toString()); passData.put(MountainPasses.MOUNTAIN_PASS_WEATHER_CONDITION, weatherCondition); passData.put(MountainPasses.MOUNTAIN_PASS_DATE_UPDATED, mDateUpdated); passData.put(MountainPasses.MOUNTAIN_PASS_CAMERA, pass.getString("Cameras")); passData.put(MountainPasses.MOUNTAIN_PASS_ELEVATION, pass.getString("ElevationInFeet")); passData.put(MountainPasses.MOUNTAIN_PASS_TRAVEL_ADVISORY_ACTIVE, pass.getString("TravelAdvisoryActive")); passData.put(MountainPasses.MOUNTAIN_PASS_ROAD_CONDITION, pass.getString("RoadCondition")); passData.put(MountainPasses.MOUNTAIN_PASS_TEMPERATURE, pass.getString("TemperatureInFahrenheit")); JSONObject restrictionOne = pass.getJSONObject("RestrictionOne"); passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_ONE, restrictionOne.getString("RestrictionText")); passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_ONE_DIRECTION, restrictionOne.getString("TravelDirection")); JSONObject restrictionTwo = pass.getJSONObject("RestrictionTwo"); passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_TWO, restrictionTwo.getString("RestrictionText")); passData.put(MountainPasses.MOUNTAIN_PASS_RESTRICTION_TWO_DIRECTION, restrictionTwo.getString("TravelDirection")); if (starred.contains(Integer.parseInt(pass.getString("MountainPassId")))) { passData.put(MountainPasses.MOUNTAIN_PASS_IS_STARRED, 1); } passes.add(passData); } // Purge existing mountain passes covered by incoming data resolver.delete(MountainPasses.CONTENT_URI, null, null); // Bulk insert all the new mountain passes resolver.bulkInsert(MountainPasses.CONTENT_URI, passes.toArray(new ContentValues[passes.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "mountain_passes" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.MOUNTAIN_PASSES_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:com.gizwits.framework.activity.BaseActivity.java
/** * ??app//from w w w.ja v a 2 s .c om */ public void exit() { if (!isExit) { isExit = true; Toast.makeText(getApplicationContext(), getString(R.string.tip_exit), Toast.LENGTH_SHORT).show(); handler.sendEmptyMessageDelayed(0, 2000); } else { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); Historys.exit(); } }
From source file:com.etime.ETimeActivity.java
/** * Callback for pressing the back button. Used to prevent the app * from destroying it self if the back button is pressed to go to * previous app/homescreen./*from w w w .j av a 2s .co m*/ */ @Override public void onBackPressed() { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(activity); if (pref.getBoolean(getString(R.string.keepInBackground), true)) { Intent setIntent = new Intent(Intent.ACTION_MAIN); setIntent.addCategory(Intent.CATEGORY_HOME); setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(setIntent); } else { super.onBackPressed(); } }
From source file:com.google.android.apps.iosched.ui.SessionDetailActivity.java
/** Build and add "notes" tab. */ private void setupNotesTab() { final TabHost host = getTabHost(); final Uri notesUri = Sessions.buildNotesDirUri(mSessionId); final Intent intent = new Intent(Intent.ACTION_VIEW, notesUri); intent.addCategory(Intent.CATEGORY_TAB); intent.putExtra(NotesActivity.EXTRA_SHOW_INSERT, true); // Notes content comes from reused activity host.addTab(//from w ww .ja v a2 s. c om host.newTabSpec(TAG_NOTES).setIndicator(buildIndicator(R.string.session_notes)).setContent(intent)); }
From source file:com.baruckis.nanodegree.spotifystreamer.PlayerService.java
private void buildNotification(NotificationCompat.Action action, boolean updateLargeIcon) { CustomTrack playSong = getCurrentTrack(); if (playSong == null) return;/*from w w w. j a v a 2 s.c o m*/ NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle(); style.setShowActionsInCompactView(0, 1, 2); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // open last activity when tapping notification Intent openAppIntent = new Intent(this, MainArtistsListActivity.class); openAppIntent.addCategory(Intent.CATEGORY_LAUNCHER); openAppIntent.setAction(Intent.ACTION_MAIN); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); builder.setSmallIcon(android.R.drawable.ic_media_play).setLargeIcon(mLargeIconBitmap) .setContentTitle(playSong.getTrackName()).setContentText(playSong.getArtistsNamesList()) .setStyle(style).setShowWhen(false) // hide time in notification .addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", ACTION_PREVIOUS)) .addAction(action).addAction(generateAction(android.R.drawable.ic_media_next, "Next", ACTION_NEXT)); if (updateLargeIcon) { Picasso.Builder picassoBuilder = new Picasso.Builder(this); Picasso picasso = picassoBuilder.build(); // to avoid too many requests when user jumps on different tracks too fast, cancel latest one. picasso.cancelRequest(mTarget); mTarget = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { mLargeIconBitmap = bitmap; builder.setLargeIcon(mLargeIconBitmap); mNotification = builder.build(); if (mShowNotification) { showCancelNotification(true); } } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; String url = playSong.getCustomImageBig().getUrl(); if (url != null) { picasso.load(url).into(mTarget); } } mNotification = builder.build(); if (mShowNotification) { showCancelNotification(true); } }
From source file:com.android.messaging.ui.UIIntentsImpl.java
@Override public void launchDocumentImagePicker(final Fragment fragment) { final Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.putExtra(Intent.EXTRA_MIME_TYPES, MessagePartData.ACCEPTABLE_IMAGE_TYPES); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(ContentType.IMAGE_UNSPECIFIED); fragment.startActivityForResult(intent, REQUEST_PICK_IMAGE_FROM_DOCUMENT_PICKER); }
From source file:io.selendroid.ServerInstrumentation.java
public void startActivity(Class activity) { if (activity == null) { SelendroidLogger.log("activity class is empty", new NullPointerException("Activity class to start is null.")); return;/*from ww w.j a va 2 s . c om*/ } finishAllActivities(); // start now the new activity Intent intent = new Intent(getTargetContext(), activity); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); Activity a = startActivitySync(intent); }