atom feed4 messages in com.googlegroups.android-developers[android-developers] Re: Trouble Open...
FromSent OnAttachments
TimbobsteveSep 26, 2008 2:25 am 
Mark MurphySep 26, 2008 4:37 am 
OCOct 16, 2008 4:28 am 
Asif kNov 17, 2008 11:09 pm 
Subject:[android-developers] Re: Trouble Opening Files via Intent
From:OC (ocr@googlemail.com)
Date:Oct 16, 2008 4:28:59 am
List:com.googlegroups.android-developers

Hello.

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();

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(android.content.Intent.ACTION_VIEW);

// Category where the App should be searched String category = new String("android.intent.category.DEFAULT");

// 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 startActivity(intent); *** CODE END ***

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

On 26 Sep., 11:25, Timbobsteve <timb@gmail.com> wrote:

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 @ anddev.org 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));                startActivity(myIntent);         } catch (ActivityNotFoundException e) {                 e.printStackTrace();         }     }

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?

Regards, Timbobsteve