Example usage for android.content Intent setData

List of usage examples for android.content Intent setData

Introduction

In this page you can find the example usage for android.content Intent setData.

Prototype

public @NonNull Intent setData(@Nullable Uri data) 

Source Link

Document

Set the data this intent is operating on.

Usage

From source file:com.xiaomi.account.utils.SysHelper.java

public static void goToEmailPage(Activity activity, String url) {
    Intent intent = new Intent("android.intent.action.VIEW");
    intent.setData(Uri.parse(url));
    intent.addFlags(67108864);/* ww  w .ja va 2  s. com*/
    intent.addFlags(268435456);
    intent.addFlags(8388608);
    activity.startActivity(intent);
}

From source file:com.game.simple.Game3.java

public static void openURL(String url) {
    Intent aIntent = new Intent(Intent.ACTION_VIEW);
    aIntent.setData(Uri.parse(url));
    self.startActivity(aIntent);/*from  w  ww  .ja  va  2  s.co  m*/

}

From source file:palamarchuk.smartlife.app.RegisterActivity.java

public static void openUrl(Context context, String url) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    context.startActivity(i);//  w w w . ja v a 2s .  co  m
}

From source file:com.adguard.android.service.FilterServiceImpl.java

public static void enableContentBlocker(Context context) {
    Intent intent = new Intent();
    intent.setAction("com.samsung.android.sbrowser.contentBlocker.ACTION_UPDATE");
    intent.setData(Uri.parse("package:com.adguard.android.contentblocker"));
    context.sendBroadcast(intent);/*from  ww w  .j  a v  a  2  s.co m*/
}

From source file:biz.bokhorst.xprivacy.Util.java

public static void viewUri(Context context, Uri uri) {
    Intent infoIntent = new Intent(Intent.ACTION_VIEW);
    infoIntent.setData(uri);
    if (isIntentAvailable(context, infoIntent))
        context.startActivity(infoIntent);
    else/*from  w ww  . jav a  2 s  .  c  o  m*/
        Toast.makeText(context, "View action not available", Toast.LENGTH_LONG).show();
}

From source file:com.andrewshu.android.reddit.common.Common.java

/**
 * //  w  w w.j  a  v  a2 s.c  o  m
 * @param url
 * @param context
 * @param requireNewTask set this to true if context is not an Activity
 * @param bypassParser
 * @param useExternalBrowser
 */
public static void launchBrowser(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);
    }

    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 (threadUrl != null)
            browser.putExtra(Constants.EXTRA_THREAD_URL, threadUrl);
        if (requireNewTask)
            browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(browser);
    }
}

From source file:com.felkertech.n.ActivityUtils.java

/**
 * Opens the correct intent to start editing the channel.
 *
 * @param activity The activity you're calling this from.
 * @param channelUrl The channel's media url.m
 *//* w  w w  .j av  a 2  s. c  om*/
public static void editChannel(final Activity activity, final String channelUrl) {
    ChannelDatabase cdn = ChannelDatabase.getInstance(activity);
    final JsonChannel jsonChannel = cdn.findChannelByMediaUrl(channelUrl);
    if (channelUrl == null || jsonChannel == null) {
        try {
            Toast.makeText(activity, R.string.toast_error_channel_invalid, Toast.LENGTH_SHORT).show();
        } catch (RuntimeException e) {
            Log.e(TAG, activity.getString(R.string.toast_error_channel_invalid));
        }
        return;
    }
    if (jsonChannel.getPluginSource() != null) {
        // Search through all plugins for one of a given source
        PackageManager pm = activity.getPackageManager();

        try {
            pm.getPackageInfo(jsonChannel.getPluginSource().getPackageName(), PackageManager.GET_ACTIVITIES);
            // Open up this particular activity
            Intent intent = new Intent();
            intent.setComponent(jsonChannel.getPluginSource());
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_ACTION, CumulusTvPlugin.INTENT_EDIT);
            Log.d(TAG, "Editing channel " + jsonChannel.toString());
            intent.putExtra(CumulusTvPlugin.INTENT_EXTRA_JSON, jsonChannel.toString());
            activity.startActivity(intent);
        } catch (PackageManager.NameNotFoundException e) {
            new MaterialDialog.Builder(activity)
                    .title(activity.getString(R.string.plugin_not_installed_title,
                            jsonChannel.getPluginSource().getPackageName()))
                    .content(R.string.plugin_not_installed_question).positiveText(R.string.download_app)
                    .negativeText(R.string.open_in_another_plugin)
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                            super.onPositive(dialog);
                            Intent i = new Intent(Intent.ACTION_VIEW);
                            i.setData(Uri.parse("http://play.google.com/store/apps/details?id="
                                    + jsonChannel.getPluginSource().getPackageName()));
                            activity.startActivity(i);
                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);
                            openPluginPicker(false, channelUrl, activity);
                        }
                    }).show();
            Toast.makeText(activity, activity.getString(R.string.toast_msg_pack_not_installed,
                    jsonChannel.getPluginSource().getPackageName()), Toast.LENGTH_SHORT).show();
            openPluginPicker(false, channelUrl, activity);
        }
    } else {
        if (DEBUG) {
            Log.d(TAG, "No specified source");
        }
        openPluginPicker(false, channelUrl, activity);
    }
}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

public static void addImageToGallery(Context c, Uri contentUri) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(contentUri);
    c.sendBroadcast(mediaScanIntent);/*from  w  ww.  j a v  a2s.co m*/
}

From source file:com.felkertech.n.ActivityUtils.java

public static void writeDriveData(final Activity context, GoogleApiClient gapi) {
    //Ask here for permission to storage
    PermissionUtils.requestPermissionIfDisabled(context, android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
            context.getString(R.string.permission_storage_rationale));
    if (PermissionUtils.isDisabled(context, android.Manifest.permission_group.STORAGE)) {
        new MaterialDialog.Builder(context).title(R.string.permission_not_allowed_error)
                .content(R.string.permission_not_allowed_text).positiveText(R.string.permission_action_settings)
                .negativeText(R.string.ok).callback(new MaterialDialog.ButtonCallback() {
                    @Override/*from   www. ja v  a  2  s .c o m*/
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);
                        Intent intent = new Intent();
                        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                        Uri uri = Uri.fromParts("package", context.getPackageName(), null);
                        intent.setData(uri);
                    }
                }).build();
    } else
        actuallyWriteData(context, gapi);
}

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?
 *///ww w  .ja  v a  2 s. com
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);
    }
}