Trouble Opening Files via Intent

by Timbobsteve » Fri, 26 Sep 2008 18:31:44 GMT

Sponsored Links
 Hi All,

I posted this in the beginners section, but received no response.
Sorry if it is bad etiquette to re-post here, it just seems that there
is a lot more activity in this list.

I am running through the FileBrowser tutorial over @ and
have it working fairly well, but the one thing I cannot get working is
Opening files when they are clicked on.

I always seem to get a "ActivityNotFoundException: no activity found
to handle { action: android.content.Intent.ACTION_VIEW data=file:///
sdcard/myfile.txt} "

My openFile() function looks like this:

    private void openFile() {
        try {
                Intent myIntent = new
Intent(android.content.Intent.ACTION_VIEW, Uri.fromFile(myFile));
        } catch (ActivityNotFoundException e) {

Can anyone see any problems with this? Is it just that there are no
Apps registered to handle opening of .png images and .txt files? Or is
my code wrong?



Trouble Opening Files via Intent

by Mark Murphy » Fri, 26 Sep 2008 19:38:10 GMT



Most likely, yes.

Mark Murphy (a Commons Guy) 
_The Busy Coder's Guide to Android Development_ Version 1.2 Published!


Sponsored Links

Trouble Opening Files via Intent

by OC » Fri, 17 Oct 2008 01:49:44 GMT


Ok, my English is not so good, but I'll try my best.

You'll have to set the correct Data and Type. You have to define the
Type by yourself, by getting the
fileextension. Type means the main MIME-type like audio/* or image/*.

For example:

You clicked at the file "MyFavouriteSong.mp3" you have to parse for
the file-extension, here ".mp3".
In the list defined by yourself (maybe in a Textfile or as a resource-
array), you look for that extension
and use the main MIME-type as Type. (should now look like "audio").
If you have the Type, you can call the "setDataAndType" Method with
parameters like
shown in the sample source below.
Android will show you a Dialog with all Application that can handle
the given Type, which did not mean
that the Application can Handle the File by itself. ;-)

*** CODE ***
// Create an Intent
Intent intent = new Intent();


                // Category where the App should be searched
                String category = new

                // Setting up the data and the type for the intent
                intent.setDataAndType(Uri.fromFile(aDirectory), type+"/

                // will start the activtiy found by android or show a
dialog to select one
*** CODE END ***

This is the way i do, but i don't know it's the right one.



Trouble Opening Files via Intent

by Asif k » Tue, 18 Nov 2008 23:11:53 GMT

 Hi OC ,

thanks for ur inputs.

  I am still getting the same exception.

Can you please clarify how you set the array and modification done in ??


Other Threads

1. search and get my maps

Hi, I'm making an android app with goolgle map API.
I'm trying to search my map that has already made, and receive the
result in kml file format.
I've tried with some URLs like :"SOME_WORDS"&output=kml
but all I can get is the placemarks data.
Then how can I get the data units of my map?
(I hope my app can gather every maps data which have some prefix words
on their titles.)
Thank you in advance.

2. will donut be available for the mytouch 3g, or just the g1?

will donut be available for the mytouch 3g or just the g1?


3. Movie.decodeStream(is) is returning NULL after updating to 1.5 SDK .

4. is possible mapview and list exist in same activity

5. TextView

6. Buying a anroid Dev in Canada?

7. Starting service in separate thread