new Intent(ACTION_VIEW, Uri.fromFile(aFile) == Exception

Put your problem here if it does not fit any of the other categories.

new Intent(ACTION_VIEW, Uri.fromFile(aFile) == Exception

Postby timbobsteve » Tue Sep 23, 2008 10:11 pm

Hi All,

First off I just wanted to say that this board is great. Between this and the Android GoogleGroups I dare say there isn't much that the Android community can't do!

Anyways, I am trying to get my hand into some Android programming (having done a little C/C++ before) and I am finding it really fun, but a little confusing in some places (e.g. the whole Context/Intent/Activity thing is completely new to me - and confusing), but all in all it is good fun.

I just wanted to post a query about some code I was writing, I was following the FileBrowser tutorials on the forums and I have hit a bit of a road block. I can't seem to open any files when they are clicked on.

First off, I'm using SDK 0.9 to compile my code, so I had to make some changes to the original stuff to get it to work. I have the onListItemClicked() funtion in place and it is being called, but my implementation of the openFile(File) method from the tutorial always seems to result in an ActivityNotFoundException. Can someone perhaps point me in the right direction?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         public void openFile(File aFile) {
  2.                 try {
  3.                         Intent newApp = new Intent(android.content.Intent.ACTION_VIEW, Uri.fromFile(aFile));
  4.                         startActivity(newApp);
  5.                 } catch (ActivityNotFoundException e) {
  6.                         e.printStackTrace();
  7.                 } catch (Exception e){
  8.                         e.printStackTrace();
  9.                 }
  10.         }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Output:
Code: Select all
android.content.ActivityNotFoundException: No Activity found to handle Intent { action=android.intent.action.VIEW data=file:///sdcard/picture.png }


I really can't seem to see what is going wrong. I don't fully understand the concept of Intents and URI's though, so perhaps I am missing something.

Any help is appreciated.

Regards,
Timbobsteve
Regards,
Timbobsteve
timbobsteve
Freshman
Freshman
 
Posts: 4
Joined: Tue Sep 23, 2008 8:58 pm

Top

Postby sinbadonline » Tue Oct 14, 2008 10:03 am

Ya, the following code will also throw a ActivityNotFoundException:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("file://" + aFile.getAbsolutePath()));
  2.  
  3. startActivity(myIntent);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


However a web address will work fine as below:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent myIntent = new Intent(Intent.ACTION_VIEW,
  2.  
  3. Uri.parse("http://www.baidu.com"));
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


So maybe need to set some other category/type, right? Anyone help to advice?
sinbadonline
Freshman
Freshman
 
Posts: 4
Joined: Mon Oct 13, 2008 10:25 am

Postby RredCat » Fri Oct 24, 2008 6:27 pm

sinbadonline wrote:Ya, the following code will also throw a ActivityNotFoundException:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("file://" + aFile.getAbsolutePath()));
  2. startActivity(myIntent);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


However a web address will work fine as below:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent myIntent = new Intent(Intent.ACTION_VIEW,
  2. Uri.parse("http://www.baidu.com"));
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


So maybe need to set some other category/type, right? Anyone help to advice?


Webrouser doesn't work with local's files. Use WebView for this purpose.
RredCat
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Oct 24, 2008 6:22 pm

Postby rmanromga » Sun Oct 26, 2008 6:41 am

Just wondering... do you have the Activity in your Application's AndoridManifest.xml file?

also to understand Intents better, take look at the Intent API docs..

http://code.google.com/android/referenc ... ntent.html

Also you mentioned that you were using the 0.9 sdk.. are you aware v1.0 sdk is already out? If I were you, I would update to the latest sdk (1.0r1) and develop using the latest sdk... believe me it cuts down on headaches down the line....

--D
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests