Android启动WebBrowser Intent会产生SecurityException

时间:2016-06-20 07:57:13

标签: android android-intent

我尝试使用以下文件将带文件的网址发送到网络活动:

public static void startDownloadFileActivity(com.app.model.File file, String link) {
    Uri uri = Uri.parse(link);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    String mime = "*/*";
    MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
    if (mimeTypeMap.hasMimeType(file.getMimeType())) {
        mime = file.getMimeType();
    } else if (mimeTypeMap.hasExtension(MimeTypeMap.getFileExtensionFromUrl(file.getTitle()))) {
        mime = mimeTypeMap.getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(file.getTitle()));
    }
    intent.setDataAndType(uri, mime);
    try {
        SDApplication.getInstance().getCurrentActivity().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Logger.logException(ERROR_TAG, "Can't find activity for mime " + mime + "\nReason:" + e.getMessage(), e);
        ToastUtils.showToast(getContext().getString(R.string.error_no_app_for_mime));
    }
}

但是当向网络浏览器发送意图时会得到:

Fatal Exception: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW dat=http://some-stand.com:10012/... typ=*/* cmp=com.google.android.apps.docs/.doclist.documentopener.WebViewOpenActivity } from ProcessRecord{4138e78 8118:com.app/u0a322} (pid=8118, uid=10322) not exported from uid 10123
   at android.os.Parcel.readException(Parcel.java:1627)
   at android.os.Parcel.readException(Parcel.java:1579)
   at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2671)
   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1509)
   at android.app.Activity.startActivityForResult(Activity.java:3963)
   at android.app.Activity.startActivityForResult(Activity.java:3924)
   at android.support.v4.app.FragmentActivity.startActivityForResult(SourceFile:820)
   at android.app.Activity.startActivity(Activity.java:4247)
   at android.app.Activity.startActivity(Activity.java:4215)
   at com.app.utils.FileUtils.startDownloadFileActivity(SourceFile:185)
   at com.app.activities.FilesActivity$1.onItemClick(SourceFile:157)
   at android.widget.AdapterView.performItemClick(AdapterView.java:310)
   at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
   at android.widget.AbsListView$PerformClick.run(AbsListView.java:3066)
   at android.widget.AbsListView$3.run(AbsListView.java:3903)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:224)
   at android.app.ActivityThread.main(ActivityThread.java:5526)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

我不明白什么权限需要应用程序来打开URL。并且只有一个设备产生错误:Sony Xperia。 应用程序在AndroidManifest文件中具有Internet权限。

1 个答案:

答案 0 :(得分:1)

检查AndroidManifest.xml中的权限。

  

android.permission.INTERNET对