问题描述
我有一个形象位于:
我想使用Android图库应用查看图像,所以我用低于code,但看起来它只是无法启动所需的活动。
变量PIC是一个包含图像的URL上面的字符串。
下面是code:
image_view.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
意向意图=新的Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(PIC),图像/ *);
startActivity(意向);
}});
堆栈:
发[< 1 GT;主](吊(例外ActivityNotFoundException))
Instrumentation.checkStartActivityResult(INT,对象)行:1408
Instrumentation.execStartActivity(上下文,的IBinder,的IBinder,活动,意图,INT)行:1378
ViewMessage(活动).startActivityForResult(意向,INT)行:2833
ViewMessage(活动).startActivity(意向)行:2939
ViewMessage $ 2.onClick(视图)行:92
ImageView的(查看).performClick()行:2408
查看$ PerformClick.run()行:8816
的ViewRoot(处理器).handleCallback(消息)线:587
的ViewRoot(处理器).dispatchMessage(消息)行:92
Looper.loop()行:123
ActivityThread.main(字符串[])行:4673
Method.invokeNative(对象,对象[],上课,下课[],类,整型,布尔)行:不可用[本机方法]
Method.invoke(对象,对象...)线:521
ZygoteInit $ MethodAndArgsCaller.run()行:858
ZygoteInit.main(字符串[])线:616
NativeStart.main(字符串[])行:不可用[本机方法]
从看清单的Gallery应用程序,它似乎并不接受图像的URL作为意图的一部分。你必须先下载图像,然后创建意图从文件系统显示的图像。
你的意图会是这样的:
意向意图=新的Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.addCategory(android.content.Intent.CATEGORY_DEFAULT);
intent.setDataAndType(Uri.parse(映像文件路径),图像/ *);
startActivity(意向);
其中,映像文件路径
是具有位置它与开头的字符串的file:/// SD卡/
I have an image located at: http://ww2.sinaimg.cn/bmiddle/8c9772a0jw1dm10273empj.jpg
I want use android gallery app to view the image, so I use below code but looks like it just can't start the desired activity.
The variable pic is a string containing above image URL.
Below is code:
image_view.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(pic), "image/*");
startActivity(intent);
}});
Stack:
Thread [<1> main] (Suspended (exception ActivityNotFoundException))
Instrumentation.checkStartActivityResult(int, Object) line: 1408
Instrumentation.execStartActivity(Context, IBinder, IBinder, Activity, Intent, int) line: 1378
ViewMessage(Activity).startActivityForResult(Intent, int) line: 2833
ViewMessage(Activity).startActivity(Intent) line: 2939
ViewMessage$2.onClick(View) line: 92
ImageView(View).performClick() line: 2408
View$PerformClick.run() line: 8816
ViewRoot(Handler).handleCallback(Message) line: 587
ViewRoot(Handler).dispatchMessage(Message) line: 92
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4673
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 858
ZygoteInit.main(String[]) line: 616
NativeStart.main(String[]) line: not available [native method]
From looking at the manifest for the Gallery application, it does not seem to accept a URL for an image as part of the Intent. You will have to download the image first, and then create the Intent to display the image from the file system.
Your Intent would be something like:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.addCategory(android.content.Intent.CATEGORY_DEFAULT);
intent.setDataAndType(Uri.parse(pathToImageFile), "image/*");
startActivity(intent);
Where pathToImageFile
is a string that has location which starts with file:///sdcard/
这篇关于使用Android意图显示来自互联网的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!