0

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

1 Answers1

1

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).

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.

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

comeGetSome
  • 1,913
  • 19
  • 20
  • i have considered Option 2: suggested by you and it worked. But i am getting error in loading three of the maps as their size is 4-5mb and app displays **unable to load file**. In my new code i have replaced my code as follows: _case (0): Intent tube = new Intent(); tube.setAction(android.content.Intent.ACTION_VIEW); tube.setDataAndType( Uri.parse("http://studentnet.kingston.ac.uk/k1059045/app_map_images/tube_map.jpg"), "image/*"); startActivity(tube); break;_ – user1938645 Apr 11 '13 at 11:11
  • Can you please guide me (or any useful link) how to apply option 1: you have suggested as it will allow user to access maps offline. please tell me the steps to follow to save image files from **assets** to **sd card**. Thank you – user1938645 Apr 11 '13 at 11:22
  • please take a look here: http://stackoverflow.com/questions/4447477/android-how-to-copy-files-in-assets-to-sdcard ,however, if your images are 5Mb in size (as a compressed JPG) I think they will take too much memory for displaying. Its not worth for a tubeMap, I guess. I would still keep them on the server but resample to a smaller size with a graphics editor, like gimp or paint.net – comeGetSome Apr 11 '13 at 12:04