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. Android graphics

Hi Im a newbe, but was thinking about creating an app for my kid,
where I take and "princess cartoon" picture, and let her fill in
colors on the different parts that I define, but Im strugling on how
to do this, if android had svg-api build in, then I could have made
the picture in inkscape, and using onthouch and fill att at the
different shapes...


2. Switch back to my application after phone call ends

>From my application I am currently launching the dialer:

newCallIntent = new Intent(Intent.ACTION_DIAL);
PhoneCallReciever receiver = new PhoneCallReciever();
startActivityForResult(newCallIntent, DIAL_RESULT);

Then I have a listener:

public void onCallStateChanged(int state, String incomingNumber) {
                        String stateString = "N/A";
                        switch (state) {
                        case TelephonyManager.CALL_STATE_IDLE:
                                stateString = "Idle";
                                IBinder wmbinder = 
                                Log.i(LOG_TAG, "WindowManager: " + wmbinder);
                                IWindowManager wm = 
                                keyUpDown(wm, KeyEvent.KEYCODE_BACK);


The goal is to then watch the call and when the phone goes IDLE I
would like to switch back to the application. How can I do this?


3. Stream Audio Android 2.1

4. Disable Button after click

5. Driver CTS - compatibility test

6. adding a view as indicator for my tabwidget

7. using eclipse run the monkeyrunner?