启动系统自带浏览器

原文地址:http://blog.csdn.net/wcs542882916

public static boolean startBrowserApp(Context ctx, String url) {
    Log.i("TAG", "startBrowserApp(Context ctx, String url) url:" + url);

    if (url == null || url.trim().isEmpty()) {
        return false;
    }
    Uri uri = Uri.parse(url);//if url is null will throw NullPointerException

    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, ctx.getPackageName());
    try {
        ctx.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Log.w("TAG", "ActivityNotFoundException intent:" + intent.toString());
        return false;
    }
    return true;
}

猜你喜欢

转载自blog.csdn.net/wcs542882916/article/details/50811752