Associating and opening a file

All your problems with Audio, Video and Images.

Associating and opening a file

Postby suslik » Mon Oct 03, 2011 5:39 am

Before I go on, I searched google and read the docs on the matters. This is one of my first attempts at making an Android app, so I may be missing something obvious, but I haven't been able to find someone with a similar problem / solution.

I am trying to make an app that associates with a file type and loads it on startup to do stuff.

Amongst other things, my AndroidManifest.xml contains this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.             <intent-filter>
  2.                 <action android:name="android.intent.action.MAIN" />
  3.                 <category android:name="android.intent.category.LAUNCHER" />
  4.                 <category android:name="android.intent.category.BROWSABLE" />
  5.             </intent-filter>
Parsed in 0.001 seconds, using GeSHi

My onCreate method (minus the irrelevant code) looks like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     public void onCreate(Bundle savedInstanceState)
  2.     {
  3.         super.onCreate(savedInstanceState);
  4.         setContentView(R.layout.main);
  6.         String file;
  7.         file = getIntent().getData().getEncodedPath();
  8.         file = Uri.decode(file);
  9.         openFile(file);
  10.     }
Parsed in 0.013 seconds, using GeSHi

and part of my open file method is this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     private String openFile(String file)
  2.     {
  3.         try {
  4.             InputStream instream = openFileInput(file);
  6.             InputStreamReader inputReader = new InputStreamReader(instream);
  7.             BufferedReader bufferedReader = new BufferedReader(inputReader);
  8. ...
  9.             instream.close();                                                                                                                    
  10.         }                                                                                                                                        
  11.         catch (IOException ex) {                                                                                                                  
  12.             ex.printStackTrace();                                                                                                                
  13.         }                                                                                                                                                                                                                                                          
  14.     }                                                                                                                                            
Parsed in 0.012 seconds, using GeSHi

My application associates with the file successfully, and I can try opening a file with it. But, I get this error:
E/AndroidRuntime(17762): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ragefororder.patchviewer/com.ragefororder.patchviewer.PatchViewerActivity}: java.lang.IllegalArgumentException: File /sdcard/bluetooth/testfile.mp3 contains a path separator

Now I googled around and so far as I understand I'm not allowed to access random files in the OS with my app... that makes sense, but if it's passed to me as part of the intent.. shouldn't I be able to? What am I doing wrong? Should I be going about this in an entirely different way?

I also threw in <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> into my AndroidManifest for good measure, it didn't really make a difference.

Please Help! BTW this is all happening on Android 3.2.
Once Poster
Once Poster
Posts: 1
Joined: Mon Oct 03, 2011 5:28 am


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 3 guests