How can I use the OpenIntents FileManager in my project?
Do I need to import the FileManager project (as library) and then extend the FileManager project from my project? Or do I need to copy the code I need?
Thank u Pely for your reply. I am a student of CSE and new to Android. I have examined the android activity life cycle, but still confused. I think the onPause() , onResume() methods are internally called, when another activity starts. Is it? or should I call them explicitly? Here is my whole code
public class AVimon extends Activity implements OnClickListener {
public MediaPlayer mp = new MediaPlayer();
public static String filename;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
public void Video()
{
VideoView video = (VideoView) findViewById(R.id.video);
// Load and start the movie
video.setVideoPath("sdcard/samplevideo.3gp");
video.start();
}
}
and I am trying the audio button, but same thing happens.
getting this in logcat
02-03 06:48:29.563: WARN/System.err(1646): at dalvik.system.NativeStart.main(Native Method)
02-03 06:48:29.563: ERROR/MediaPlayer(1646): start called in state 0
02-03 06:48:29.563: ERROR/MediaPlayer(1646): error (-38, 0)
02-03 06:48:29.563: ERROR/MediaPlayer(1646): Error (-38,0)
02-03 06:48:29.593: ERROR/MediaPlayer(1646): Error (-38,0)
02-03 06:48:29.723: WARN/IInputConnectionWrapper(1582): showStatusIcon on inactive InputConnection
my Audio(String path) method works with a given file path like Audio("sdcard/a pare mukor.mp3").
I am trying to examine the oi notepad code, but when I import the code to eclipse, it shows many errors. I am using the latest android sdk. The same thing happens if I import filemanager 1.1.3 code.
They are prepared for use with the latest Android SDK. (They will be available soon as downloads, but it may take another week or so until all testing has finished.)
After onActivityResult(), your activity is resumed with onResume().
You have to store the file name in a local variable.
Please have a look at the "File Manager Demo" how to do that.
I would recommend that you try to show that file name on the screen in a text view or output it in logcat. Then you see what is wrong - even before you launch the audio.
Dear Peli,
Thank you very much. My problem is resolved following your instruction. The problem was - after using data.getDataString() method in onActivityResult the string path contained %20 instead of white spaces. So, I have used filename = data.getDataString().replaceAll("%20", " ");. Now it is okay.
And the notepad is successfully imported in Eclipse and is running well using subversion.
Let me know if there is any better method to parse the file name containing white spaces rather than data.getDataString().replaceAll("%20", " ");
I don't see anything in the OI File Manager developer information about how to ensure that the user's phone has the OI File Manager installed. In other words, imagine the user has installed my app, and my app executes:
Intent intent = new Intent("org.openintents.action.PICK_FILE");
startActivityForResult(intent, 1);
How do I ensure that the user's phone has OI File Manager so that it can handle the Intent?
returning file path
Hello,
I am trying to integrate this file manager to select song from the sd card to play in my media player program. So I coded like below
Intent intent = new Intent("org.openintents.action.PICK_FILE");
startActivityForResult(intent, 1);
mp.reset();
Audio(filepath);
Where file path is a string input containing the path of the song...
I am getting this error....
02-02 22:08:01.853: INFO/ActivityManager(67): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=imon.test.android/.AVimon } from pid 113
02-02 22:08:03.183: INFO/ActivityManager(67): Displayed imon.test.android/.AVimon: +1s65ms
02-02 22:08:04.413: INFO/ActivityManager(67): Starting: Intent { act=org.openintents.action.PICK_FILE cmp=org.openintents.filemanager/.FileManagerActivity } from pid 589
02-02 22:08:04.433: ERROR/MediaPlayer(589): stop called in state 1
02-02 22:08:04.433: ERROR/MediaPlayer(589): error (-38, 0)
02-02 22:08:04.443: WARN/System.err(589): java.lang.IllegalArgumentException
02-02 22:08:04.453: WARN/System.err(589): at android.media.MediaPlayer.setDataSource(Native Method)
02-02 22:08:04.453: WARN/System.err(589): at imon.test.android.AVimon.Audio(AVimon.java:96)
02-02 22:08:04.463: WARN/System.err(589): at imon.test.android.AVimon.onClick(AVimon.java:57)
02-02 22:08:04.463: WARN/System.err(589): at android.view.View.performClick(View.java:2485)
I am feeling like my program is not waiting for the intent to be returned and executing to the next line without waiting......
Please help me to solve this.
You have to read out the
You have to read out the result of the intent in onActivityResult().
Please refer to the TestFileManager (File Manager Demo) application
http://code.google.com/p/openintents/downloads/list?can=2&q=oi+file+manager
or read here:
http://developer.android.com/guide/appendix/faq/commontasks.html#returni...
Be sure you understand Android's activity life cycle, because you will switch activities between your own and OI File Manager's activities.
Want to test an app which uses and returns the file path
Thank u Pely for your reply. I am a student of CSE and new to Android. I have examined the android activity life cycle, but still confused. I think the onPause() , onResume() methods are internally called, when another activity starts. Is it? or should I call them explicitly? Here is my whole code
package imon.test.android;
import org.openintents.intents.FileManagerIntents;
import java.io.IOException;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.VideoView;
public class AVimon extends Activity implements OnClickListener {
public MediaPlayer mp = new MediaPlayer();
public static String filename;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View audioButton = findViewById(R.id.audio_button);
audioButton.setOnClickListener(this);
View videoButton = findViewById(R.id.video_button);
videoButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.video_button:
mp.reset();
mp.release();
setContentView(R.layout.video);
Video();;
break;
case R.id.audio_button:
//Intent j = new Intent(this, FileManager.class);
//Intent k = new Intent();
//startActivity(j);
Intent intent = new Intent("org.openintents.action.PICK_FILE");
startActivityForResult(intent, 1);
//mp.reset();
//Audio(filename);
break;
case R.id.exit_button:
mp.release();
finish();
break;
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String filename = data.getDataString();
if (filename != null) {
// Get rid of URI prefix:
if (filename.startsWith("file://")) {
filename = filename.substring(7);
}
Audio(filename);
//AVimon.filename = filename;
}
}
/*public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
Audio();
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
Video();
break;
}
return true;
}
*/
public void Audio(String path)
{
// Create a new MediaPlayer to play this sound
// mp = MediaPlayer.create(this, resId);
mp = new MediaPlayer();
if (mp != null) {
mp.stop();
}
try
{
mp.setDataSource(path);
mp.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}
public void Video()
{
VideoView video = (VideoView) findViewById(R.id.video);
// Load and start the movie
video.setVideoPath("sdcard/samplevideo.3gp");
video.start();
}
}
and I am trying the audio button, but same thing happens.
getting this in logcat
02-03 06:48:29.563: WARN/System.err(1646): at dalvik.system.NativeStart.main(Native Method)
02-03 06:48:29.563: ERROR/MediaPlayer(1646): start called in state 0
02-03 06:48:29.563: ERROR/MediaPlayer(1646): error (-38, 0)
02-03 06:48:29.563: ERROR/MediaPlayer(1646): Error (-38,0)
02-03 06:48:29.593: ERROR/MediaPlayer(1646): Error (-38,0)
02-03 06:48:29.723: WARN/IInputConnectionWrapper(1582): showStatusIcon on inactive InputConnection
my Audio(String path) method works with a given file path like Audio("sdcard/a pare mukor.mp3").
I am trying to examine the oi notepad code, but when I import the code to eclipse, it shows many errors. I am using the latest android sdk. The same thing happens if I import filemanager 1.1.3 code.
Please check out the latest
Please check out the latest code from the trunk using SVN:
http://code.google.com/p/openintents/source/checkout
They are prepared for use with the latest Android SDK. (They will be available soon as downloads, but it may take another week or so until all testing has finished.)
After onActivityResult(), your activity is resumed with onResume().
You have to store the file name in a local variable.
Please have a look at the "File Manager Demo" how to do that.
I would recommend that you try to show that file name on the screen in a text view or output it in logcat. Then you see what is wrong - even before you launch the audio.
it's working
Dear Peli,
Thank you very much. My problem is resolved following your instruction. The problem was - after using data.getDataString() method in onActivityResult the string path contained %20 instead of white spaces. So, I have used filename = data.getDataString().replaceAll("%20", " ");. Now it is okay.
And the notepad is successfully imported in Eclipse and is running well using subversion.
Let me know if there is any better method to parse the file name containing white spaces rather than data.getDataString().replaceAll("%20", " ");
Thank you again
Regards,
imon
Bangladesh
Use data.getPath() which
Use data.getPath() which automatically decodes the path.
Functional requirements
Dear Ben,
It's a must to post your requirements, in order to give you a usable answer
Kind regards
Why?
Why? I think it must be not soo hard to get this done.
Using OI File manager
You do not need to include the OI File manager in your project if you simply want to use it to select files.
Simply follow the instructions given here:
http://www.openintents.org/en/node/159
in the section "Information for developers"
There is also a sample application that you can download and study.
Let me know if you have further questions.
Peli
How do we ensure that the user has the OI File Manager
I don't see anything in the OI File Manager developer information about how to ensure that the user's phone has the OI File Manager installed. In other words, imagine the user has installed my app, and my app executes:
Intent intent = new Intent("org.openintents.action.PICK_FILE");
startActivityForResult(intent, 1);
How do I ensure that the user's phone has OI File Manager so that it can handle the Intent?
Thanks!
Stephen