List of usage examples for android.content Intent addFlags
public @NonNull Intent addFlags(@Flags int flags)
From source file:com.lee.sdk.utils.Utils.java
/** * ????/*from w ww . ja v a 2 s .com*/ * * @param activity ?Activity??? * @param nameId ???? * @param iconId ?? * @param appendFlags ????IntentFlag */ public static void addShortcut(Activity activity, int nameId, int iconId, int appendFlags) { Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // ???? shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(nameId)); shortcut.putExtra("duplicate", false); // ???? // ?Activity??? ComponentName comp = new ComponentName(activity.getPackageName(), activity.getClass().getName()); Intent intent = new Intent(Intent.ACTION_MAIN).setComponent(comp); if (appendFlags != 0) { intent.addFlags(appendFlags); } shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); // ?? ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(activity, iconId); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); activity.sendBroadcast(shortcut); }
From source file:com.manning.androidhacks.hack023.HackApplication.java
public Account getCurrentAccount() { AccountManager accountManager = AccountManager.get(this); Account[] accounts = accountManager.getAccountsByType(AuthenticatorActivity.PARAM_ACCOUNT_TYPE); if (accounts.length > 0) { return accounts[0]; } else {/*from w ww . j a va 2s.c om*/ Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); return null; } }
From source file:in.shick.diode.common.Common.java
/** * * @param settings The {@link RedditSettings} object used to for preference-retrieving. * @param context The {@link Context} object to use, as necessary. * @param url The URL to launch in the browser. * @param threadUrl The (optional) URL of the comments thread for the 'View comments' menu option in the browser. * @param requireNewTask set this to true if context is not an Activity * @param bypassParser Should URI parsing be bypassed, usually true in the case an external browser is being launched. * @param useExternalBrowser Should the external browser app be launched instead of the internal one. * @param saveHistory Should the URL be entered into the browser history? *//*from w ww . j a v a 2s. c o m*/ public static void launchBrowser(RedditSettings settings, Context context, String url, String threadUrl, boolean requireNewTask, boolean bypassParser, boolean useExternalBrowser, boolean saveHistory) { try { if (saveHistory) { Browser.updateVisitedHistory(context.getContentResolver(), url, true); } } catch (Exception ex) { if (Constants.LOGGING) Log.i(TAG, "Browser.updateVisitedHistory error", ex); } boolean forceDesktopUserAgent = false; if (!bypassParser && settings != null && settings.isLoadImgurImagesDirectly()) { Matcher m = m_imgurRegex.matcher(url); if (m.matches() && m.group(1) != null) { // We've determined it's an imgur link, no need to parse it further. bypassParser = true; url = "http://i.imgur.com/" + m.group(1); if (!StringUtils.isEmpty(m.group(2))) { String extension = m.group(2); if (".gifv".equalsIgnoreCase(extension)) { extension = ".mp4"; } url += extension; } else { // Need to give images an extension, or imgur will redirect to the mobile site. url += ".png"; } forceDesktopUserAgent = true; } } if (settings != null && settings.isLoadVredditLinksDirectly()) { if (url.contains("v.redd.it")) { url += "/DASH_600_K"; } } Uri uri = Uri.parse(url); if (!bypassParser) { if (Util.isRedditUri(uri)) { String path = uri.getPath(); Matcher matcher = COMMENT_LINK.matcher(path); if (matcher.matches()) { if (matcher.group(3) != null || matcher.group(2) != null) { CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } } matcher = REDDIT_LINK.matcher(path); if (matcher.matches()) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } matcher = USER_LINK.matcher(path); if (matcher.matches()) { Intent intent = new Intent(context, ProfileActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } } else if (Util.isRedditShortenedUri(uri)) { String path = uri.getPath(); if (path.equals("") || path.equals("/")) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { // Assume it points to a thread aka CommentsList CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } return; } } uri = Util.optimizeMobileUri(uri); // Some URLs should always be opened externally, if BrowserActivity doesn't support their content. if (Util.isYoutubeUri(uri) || Util.isAndroidMarketUri(uri)) { useExternalBrowser = true; } if (useExternalBrowser) { Intent browser = new Intent(Intent.ACTION_VIEW, uri); browser.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); if (requireNewTask) { browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.startActivity(browser); } else { Intent browser = new Intent(context, BrowserActivity.class); browser.setData(uri); if (forceDesktopUserAgent) { browser.putExtra(Constants.EXTRA_FORCE_UA_STRING, "desktop"); } if (threadUrl != null) { browser.putExtra(Constants.EXTRA_THREAD_URL, threadUrl); } if (requireNewTask) { browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.startActivity(browser); } }
From source file:gov.in.bloomington.georeporter.fragments.ServersFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); JSONObject current_server = null;/* w w w .j av a 2s . c o m*/ try { current_server = mServers.getJSONObject(position); } catch (JSONException e) { // We'll just pass null to Preferences, which will wipe current_server // Once they get sent to Home, home will realize there isn't // a current_server and send them back here } Preferences.setCurrentServer(current_server, getActivity()); Intent i = new Intent(getActivity(), MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); }
From source file:com.marianhello.bgloc.BootCompletedReceiver.java
@Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "Received boot completed"); ConfigurationDAO dao = DAOFactory.createConfigurationDAO(context); Config config = null;//from www . j a v a 2 s .c o m try { config = dao.retrieveConfiguration(); } catch (JSONException e) { //noop } if (config == null) { return; } Log.d(TAG, "Boot completed " + config.toString()); if (config.getStartOnBoot()) { Log.i(TAG, "Starting service after boot"); Intent locationServiceIntent = new Intent(context, LocationService.class); locationServiceIntent.addFlags(Intent.FLAG_FROM_BACKGROUND); locationServiceIntent.putExtra("config", config); context.startService(locationServiceIntent); } }
From source file:com.xmartlabs.cordova.market.Market.java
/** * Open the appId details on Google Play . * * @param appId/*from w w w . j a v a 2 s .com*/ * Application Id on Google Play. * E.g.: com.google.earth */ private void openGooglePlay(String appId) throws android.content.ActivityNotFoundException { Context context = this.cordova.getActivity().getApplicationContext(); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appId)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); }
From source file:com.liferay.mobile.sample.task.callback.ContactCallback.java
@Override public void onSuccess(Contact contact) { _user.setContact(contact);//from w w w.j av a2 s. co m Intent intent = new Intent(_context, DetailsActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); intent.putExtra(DetailsActivity.EXTRA_USER, _user); _context.startActivity(intent); }
From source file:com.chefsglass.StopwatchService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (mLiveCard == null) { mLiveCard = new LiveCard(this, LIVE_CARD_TAG); new GetRecipeTask(new GetRecipeRequest(1l)).execute(); // Keep track of the callback to remove it before unpublishing. mCallback = new RecipeDrawer(this); mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback); Intent menuIntent = new Intent(this, MenuActivity.class); menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0)); mLiveCard.attach(this); mLiveCard.publish(PublishMode.REVEAL); } else {/*from w ww . j a v a2 s.c om*/ mLiveCard.navigate(); } return START_STICKY; }
From source file:fr.cph.stock.android.StockTrackerApp.java
/** * This function logout the user and removes its login/password from the preferences. It also loads the login activity * /*from www . j a v a 2s . c o m*/ * @param activity * the activity to finish */ public void logOut(Activity activity) { SharedPreferences settings = getSharedPreferences(BaseActivity.PREFS_NAME, 0); String login = settings.getString("login", null); String password = settings.getString("password", null); if (login != null) { settings.edit().remove("login").commit(); } if (password != null) { settings.edit().remove("password").commit(); } activity.setResult(100); activity.finish(); Intent intent = new Intent(this, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); }
From source file:br.ajmarques.cordova.plugin.localnotification.ReceiverActivity.java
/** * Launch main intent for package./* w w w . j a va2 s .co m*/ */ private void launchMainIntent() { Context context = getApplicationContext(); String packageName = context.getPackageName(); Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName); launchIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); context.startActivity(launchIntent); }