从web获取图像时出现android.content.ActivityNotFoundException

时间:2012-08-03 09:14:27

标签: android rest service web

每当我想使用Android中的内置图库来显示来自网络的图片时,我都会收到此错误。

08-03 10:12:59.895: E/AndroidRuntime(27974): FATAL EXCEPTION: main
08-03 10:12:59.895: E/AndroidRuntime(27974): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://192.168.10.132:8000/someimage.jpg typ=image/* }
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.app.Activity.startActivityForResult(Activity.java:2827)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.app.Activity.startActivity(Activity.java:2933)
08-03 10:12:59.895: E/AndroidRuntime(27974): at my.package.activities.MediaActivity$2.onItemClick(MediaActivity.java:58)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1936)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.os.Handler.handleCallback(Handler.java:587)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.os.Handler.dispatchMessage(Handler.java:92)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.os.Looper.loop(Looper.java:123)
08-03 10:12:59.895: E/AndroidRuntime(27974): at android.app.ActivityThread.main(ActivityThread.java:3687)
08-03 10:12:59.895: E/AndroidRuntime(27974): at java.lang.reflect.Method.invokeNative(Native Method)
08-03 10:12:59.895: E/AndroidRuntime(27974): at java.lang.reflect.Method.invoke(Method.java:507)
08-03 10:12:59.895: E/AndroidRuntime(27974): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-03 10:12:59.895: E/AndroidRuntime(27974): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-03 10:12:59.895: E/AndroidRuntime(27974): at dalvik.system.NativeStart.main(Native Method)

我的代码是:

gridView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
        Media clicked = adapter.getItem(position);

        String url = Backend.BASE_MEDIA_URL + clicked.url_big;

        Log.d("Media", url);

        Intent intent = new Intent();  
        intent.setAction(android.content.Intent.ACTION_VIEW);   
        intent.setDataAndType(Uri.parse(url), "image/*");  
        startActivity(intent);  
    }
});

我100%肯定网址是正确的。提前谢谢。

编辑:清单文件,我删除了一些无关的活动

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="my.package" android:versionCode="1"
    android:versionName="1">

    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCOUNT_MANAGER" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >


        <activity android:name=".android.intent.action.VIEW" ></activity>

    </application>

</manifest>

1 个答案:

答案 0 :(得分:1)

  

每次我想使用Android中的内置图库来显示来自网络的图片时,我都会收到此错误

首先,没有单一的“build in gallery”应用程序。有数百个设备,他们将有各种“内置画廊”应用程序。

其次,除了浏览器之外,您的设备上没有任何内容能够“显示来自网络的图像”,并且只有当您让Android确定实际的具体MIME类型时才会这样。不要求任何设备的“内置图库”应用程序支持使用它来下载和显示图像的第三方应用程序。