List of usage examples for android.content Intent addCategory
public @NonNull Intent addCategory(String category)
From source file:com.example.android.threadsample.BroadcastNotifier.java
/** * Uses LocalBroadcastManager to send an {@link String} containing a logcat message. * {@link Intent} has the action {@code BROADCAST_ACTION} and the category {@code DEFAULT}. * * @param logData a {@link String} to insert into the log. *///w w w .j a v a2s.co m public void notifyProgress(String logData) { Intent localIntent = new Intent(); // The Intent contains the custom broadcast action for this app localIntent.setAction(Constants.BROADCAST_ACTION); localIntent.putExtra(Constants.EXTENDED_DATA_STATUS, -1); // Puts log data into the Intent localIntent.putExtra(Constants.EXTENDED_STATUS_LOG, logData); localIntent.addCategory(Intent.CATEGORY_DEFAULT); // Broadcasts the Intent mBroadcaster.sendBroadcast(localIntent); }
From source file:cc.metapro.openct.myclass.ClassActivity.java
private void showFilerChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try {//from ww w.j a v a 2 s . c om startActivityForResult(Intent.createChooser(intent, getString(R.string.select_schedule_file)), FILE_SELECT_CODE); } catch (ActivityNotFoundException ex) { Toast.makeText(this, R.string.fail_file_chooser, Toast.LENGTH_LONG).show(); } }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
@SuppressWarnings("deprecation") public Notification createNotification(Bundle settings, JSONObject obj) { // notifications[i] = api.normalizeAPI({ // 'string': { // mandatory: ['title', 'body'], // defaults: {'icon':'icon'} // },//from w w w .ja v a2 s . co m // // 'number': { // mandatory: ['id', 'timeMillisSince1970'], // // the number of ms after which we start prioritising more recent // things above you. // defaults: {'epsilon': 1000 * 60 * 24 * 365} // }, // // 'boolean': { // defaults: { // 'vibrate': false, // 'sound': false // } // } int icon = settings.getInt("notification_icon", -1); if (icon == -1) { Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver"); return null; } Notification n = new Notification(); n.icon = icon; n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; long alarmTime = obj.optLong("timeMillisSince1970"); long displayTime = obj.optLong("displayTimestamp", alarmTime); n.when = displayTime; n.tickerText = obj.optString("body"); n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null); if (obj.optBoolean("vibrate")) { n.defaults |= Notification.DEFAULT_VIBRATE; } if (obj.optBoolean("sound")) { n.defaults |= Notification.DEFAULT_SOUND; } String uriString = settings.getString("content_uri_prefix"); if (uriString == null) { Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver"); return null; } if (uriString.contains("%d")) { uriString = String.format(uriString, obj.optInt("id")); } Uri uri = Uri.parse(uriString); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(uri); n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT); return n; }
From source file:com.cryart.sabbathschool.ui.activity.SSMainActivity.java
@Override public void onBackPressed() { if (_SSDrawerLayout.isDrawerOpen(Gravity.START)) { _SSDrawerLayout.closeDrawer(Gravity.START); } else {//from ww w .j a va 2 s . c om Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesTerminalSailingSpaceSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;// w w w . j av a 2s . com long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy h:mm a"); /** * 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[] { "ferries_terminal_sailing_space" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.SECOND_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(); try { URL url = new URL(TERMINAL_SAILING_SPACE_URL); URLConnection urlConn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONArray array = new JSONArray(jsonFile); List<ContentValues> terminal = new ArrayList<ContentValues>(); int numItems = array.length(); for (int j = 0; j < numItems; j++) { JSONObject item = array.getJSONObject(j); ContentValues sailingSpaceValues = new ContentValues(); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_ID, item.getInt("TerminalID")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_NAME, item.getString("TerminalName")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_ABBREV, item.getString("TerminalAbbrev")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_DEPARTING_SPACES, item.getString("DepartingSpaces")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_LAST_UPDATED, dateFormat.format(new Date(System.currentTimeMillis()))); if (starred.contains(item.getInt("TerminalID"))) { sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_IS_STARRED, 1); } terminal.add(sailingSpaceValues); } // Purge existing terminal sailing space items covered by incoming data resolver.delete(FerriesTerminalSailingSpace.CONTENT_URI, null, null); // Bulk insert all the new terminal sailing space items resolver.bulkInsert(FerriesTerminalSailingSpace.CONTENT_URI, terminal.toArray(new ContentValues[terminal.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[] { "ferries_terminal_sailing_space" }); responseString = "OK"; } catch (Exception e) { Log.e(TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent .setAction("gov.wa.wsdot.android.wsdot.intent.action.FERRIES_TERMINAL_SAILING_SPACE_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:bg.mentormate.academy.reservations.activities.BroadcastNotifier.java
/** * Uses LocalBroadcastManager to send an {@link String} containing a logcat message. * {@link android.content.Intent} has the action {@code BROADCAST_ACTION} and the category {@code DEFAULT}. * * @param logData a {@link String} to insert into the log. *//* w ww .j a v a 2 s.c o m*/ public void notifyProgress(String logData) { Intent localIntent = new Intent(); // The Intent contains the custom broadcast action for this app localIntent.setAction(DBConstants.BROADCAST_ACTION); localIntent.putExtra(DBConstants.EXTENDED_DATA_STATUS, -1); // Puts log data into the Intent localIntent.putExtra(DBConstants.EXTENDED_STATUS_LOG, logData); localIntent.addCategory(Intent.CATEGORY_DEFAULT); // Broadcasts the Intent mBroadcaster.sendBroadcast(localIntent); }
From source file:io.indy.drone.service.ScheduledService.java
@Override protected void onHandleIntent(Intent intent) { ifd("onHandleIntent"); boolean isPullToRefresh = intent.getBooleanExtra(StrikeListActivity.ResponseReceiver.IS_PTR, false); if (isPullToRefresh) { ifd("invoked service via pull to refresh"); }//w w w .j a va 2 s .co m mDatabase = new SQLDatabase(this); // called by a repeating alarm so update sharedpreferences with the current time updateAlarmTime(); try { int serverCount = fetchStrikesCount(); int localCount = mDatabase.getNumStrikes(); if (localCount == 0) { ifd("localCount == 0"); return; } if (localCount < serverCount) { // there's new strike data in the server ifd("new strike data found on server"); JSONArray jsonStrikes = fetchNewStrikes(localCount); if (jsonStrikes == null) { ifd("fetching new strike data returned null"); return; } ifd("adding strike data to local db"); addStrikes(jsonStrikes); // event to inform list that new strike data is in the db EventBus.getDefault().post(new UpdatedDatabaseEvent()); // create a notification if (!isPullToRefresh) { createNotification(); } } else { ifd("serverCount (" + serverCount + ") not greater than localCount (" + localCount + ")"); } if (isPullToRefresh) { Intent broadcastIntent = new Intent(); broadcastIntent.setAction(StrikeListActivity.ResponseReceiver.ACTION_RESP); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); int diff = serverCount - localCount; broadcastIntent.putExtra(StrikeListActivity.ResponseReceiver.STRIKE_DIFF, diff); sendBroadcast(broadcastIntent); } } catch (Exception e) { e.printStackTrace(); } }
From source file:net.openid.appauthdemo.Configuration.java
private boolean isRedirectUriRegistered() { // ensure that the redirect URI declared in the configuration is handled by some activity // in the app, by querying the package manager speculatively Intent redirectIntent = new Intent(); redirectIntent.setPackage(mContext.getPackageName()); redirectIntent.setAction(Intent.ACTION_VIEW); redirectIntent.addCategory(Intent.CATEGORY_BROWSABLE); redirectIntent.setData(mRedirectUri); return !mContext.getPackageManager().queryIntentActivities(redirectIntent, 0).isEmpty(); }
From source file:com.example.android.wifidirect.BroadcastNotifier.java
/** * * Uses LocalBroadcastManager to send an {@link Intent} containing {@code status}. The * {@link Intent} has the action {@code BROADCAST_ACTION} and the category {@code DEFAULT}. * * @param status {@link Integer} denoting a work request status *//*from w ww .j ava 2s . c o m*/ public void broadcastIntentWithMessage(String msg) { //\todo - KH probably want to change this to take a string logData instead of int status Intent localIntent = new Intent(); // The Intent contains the custom broadcast action for this app localIntent.setAction(Constants.BROADCAST_ACTION); // Puts the status into the Intent localIntent.putExtra(Constants.EXTENDED_DATA_STATUS, -1); // Puts log data into the Intent localIntent.putExtra(Constants.EXTENDED_STATUS_LOG, msg); localIntent.addCategory(Intent.CATEGORY_DEFAULT); // Broadcasts the Intent mBroadcaster.sendBroadcast(localIntent); }
From source file:com.krayzk9s.imgurholo.activities.ImgurHoloActivity.java
public void imageSelected(ArrayList<JSONParcelable> data, int position) { FrameLayout displayFrag = (FrameLayout) findViewById(R.id.frame_layout_child); if (displayFrag == null) { // DisplayFragment (Fragment B) is not in the layout (handset layout), // so start DisplayActivity (Activity B) // and pass it the info about the selected item if (getApiCall().settings.getBoolean("ImagePagerEnabled", false) == false) { Intent intent = new Intent(); intent.putExtra("id", data.get(position)); Log.d("data", data.get(position).toString()); intent.setAction(ImgurHoloActivity.IMAGE_INTENT); intent.addCategory(Intent.CATEGORY_DEFAULT); startActivity(intent);//from w w w .java2 s . com } else { Intent intent = new Intent(); intent.putExtra("ids", data); intent.putExtra("start", position); intent.setAction(ImgurHoloActivity.IMAGE_PAGER_INTENT); intent.addCategory(Intent.CATEGORY_DEFAULT); startActivity(intent); } } else { // DisplayFragment (Fragment B) is in the layout (tablet layout), // so tell the fragment to update try { if (data.get(position).getJSONObject().has("is_album") && data.get(position).getJSONObject().getBoolean("is_album")) { ImagesFragment fragment = new ImagesFragment(); Bundle bundle = new Bundle(); bundle.putString("imageCall", "3/album/" + data.get(position).getJSONObject().getString("id")); bundle.putString("id", data.get(position).getJSONObject().getString("id")); bundle.putParcelable("albumData", data.get(position)); fragment.setArguments(bundle); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.frame_layout_child, fragment).commitAllowingStateLoss(); } else { SingleImageFragment singleImageFragment = new SingleImageFragment(); Bundle bundle = new Bundle(); bundle.putBoolean("gallery", true); bundle.putParcelable("imageData", data.get(position)); singleImageFragment.setArguments(bundle); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.frame_layout_child, singleImageFragment) .commitAllowingStateLoss(); } } catch (JSONException e) { Log.e("Error!", e.toString()); } } }