使用电话的图像查看器通过隐式意图从资产文件夹加载图像时出错 [英] Error Loading image from asset folder through Implicit Intent by using Phone's Image viewer

查看:71
本文介绍了使用电话的图像查看器通过隐式意图从资产文件夹加载图像时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用隐式Intent通过移动设备的相机图像查看器应用程序显示不同的伦敦地铁地图.我在资产文件夹中有 tube_map.gif 图片文件,但是当我尝试加载该文件时,应用程序显示找不到项目.我认为我指定的文件路径不正确.我关注了以下视频.唯一的区别是,在视频中,图像文件存储在手机的SD卡中,而在我的情况下,图像文件存储在资产文件夹中. 可以通过此链接查看视频.我的代码如下:

I am trying to display different London Tube maps through mobile's camera image viewer app by using implicit Intent. I had tube_map.gif image file in asset folder but when i try to load this file, app displays unable to find item. I think the file path i am specifying is not correct. I have followed the following video. the only difference is that in video, image file is stored on phone's SD Card while in my case, it is stored in asset folder. Video can be seen by this link. My code is as follows:

package uk.ac.kingston.mobileTechnology.k1059045.trainCountdown;

import java.io.File;

import uk.ac.kingston.mobileTechnology.k1059045.trainCountdown.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.Toast;

public class ViewTubeMap extends Activity{

String[] maps = {"TUBE","NATIONAL RAIL","OVERGROUND","DLR","TRAMLINK","RIVER BUS","TOURISTS (Tube Map)","TOURISTS (Bus Map)","RAIL CONNECTIONS","TOILET FACILITIES"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.tube_map_layout);

     AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Pick a Map");
               builder.setItems(maps, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int which) {
                   // The 'which' argument contains the index position
                   // of the selected item
                       switch(which){

                       case(0):
                           makeToast("Case 0");
                           Intent intent = new Intent();
                                   intent.setAction(android.content.Intent.ACTION_VIEW);
                           File image = new File("assets/tube_map.gif");
                           intent.setDataAndType(Uri.fromFile(image), "image/*");
                           startActivity(intent);
                           break;

                       case(1):
                           makeToast("Case 1");
                           break;
                       case(2):
                           makeToast("Case 2");
                           break;
                       case(3):
                           makeToast("Case 3");
                           break;
                       case(4):
                           makeToast("Case 4");
                           break;
                       case(5):
                           makeToast("Case 5");
                           break;
                       case(6):
                           makeToast("Case 6");
                           break;
                       case(7):
                           makeToast("Case 7");
                           break;
                       case(8):
                           makeToast("Case 8");
                           break;
                       case(9):
                           makeToast("Case 9");
                           break;
                       }
               }
        });

       builder.create();
       builder.show();
}

public void makeToast(String message) {
    Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
}

任何人都可以指导我我的代码有什么问题,或者如何访问我的图像并将其显示在手机的相机图像查看应用程序中?谢谢

can anyone please guide me what's wrong with my code or how can i access my image and display it in phone's camera image view app? Thanks

推荐答案

资产是应用程序的私有区域,因此,很幸运没有其他应用程序可以访问其他应用程序的该区域.我可以通过SD卡(选项1)进行变通,或者通过互联网(非本地)提供tubeMap,然后从那里获取图像(选项2).

assets is a private area of an app, so, fortunately no other app can access this area of another app. I would either make a workaround via SD card (option 1) or make the tubeMaps available via the internet (not locally) and obtain images from there (option 2).

选项1: 您添加了访问外部存储的权限.在活动开始时,您将图像从本地资产同步到外部存储,然后稍微更改代码以将另一个文件对象以及ACTION_VIEW意图指向外部存储.

Option 1: you add a permission to access external storage. On the activity start you synchronize the images from local assets to external storage and then slightly change your code to pass another file object along with ACTION_VIEW intent pointing to external storage.

选项2: 您将试管图上传到互联网上的某个地方,并提供指向ACTION_VIEW目的的网址.

Option 2: you upload the tubemaps somewhere on the internet and provide a url to the ACTION_VIEW intent.

这篇关于使用电话的图像查看器通过隐式意图从资产文件夹加载图像时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆