如何更改默认浏览器?

时间:2016-12-17 16:39:00

标签: android

我希望我的按钮调出默认浏览器选择器以处理操作。我试过这个,但是这个实现并没有带来默认的浏览器选择器。我在哪里?

Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://"));  
    ResolveInfo resolveInfo = getPackageManager().resolveActivity(browserIntent,PackageManager.MATCH_DEFAULT_ONLY);

    // This is the default browser's packageName
    String packageName = resolveInfo.activityInfo.packageName;

编辑::

public void setdef(View view) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));
    String title = "Select browser";
    Intent chooser = Intent.createChooser(intent, title);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(chooser);
    }
}


<Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="setdef"
    android:text="Button" />

0 个答案:

没有答案
相关问题