I am create an directory to put audio files created by my app. The directory is on the SD card.
But if people modify that folder on the SD card manually then how can my app detect that event and rename the path to save the audios in the app? Or if the folder is deleted can it be detected too?
And another question:
Assume that the audio files created in a special folder on the SD card are listed to a ListView
. (Application.onCreate
automatically lists all audio files created by the application that exist in that special folder).
Now we exit from the app and go to that folder and copy another audio not created by my app there. Now we run the app again. That copied audio mustn't show as a created audio file because it doesn't actually belong my program. Is that possible?
how understands my app that an copied audio file from other place to folder that belongs with my program is not belong it surely...
this idea i was that every time an audio created then listing all audio on my folder on sdcard again. but this some problem,because maybe people chagne or modify(such as copy other audios to my folder or rename that or modify one of audios by cut or merge) now app how understand this event? your help will be appreciate...
UPDATE: I read this link and found this: Using Shared Preferences
The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
User Preferences
Shared preferences are not strictly for saving "user preferences," such as what ringtone a user has chosen. If you're interested in creating user preferences for your application, see PreferenceActivity, which provides an Activity framework for you to create user preferences, which will be automatically persisted (using shared preferences).
To get a SharedPreferences object for your application, use one of two methods: •getSharedPreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter. •getPreferences() - Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don't supply a name.
To write values: 1.Call edit() to get a SharedPreferences.Editor.
2.Add values with methods such as putBoolean() and putString().
3.Commit the new values with commit()
To read values, use SharedPreferences methods such as getBoolean() and getString().
Here is an example that saves a preference for silent keypress mode in a calculator:
public class Calc extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
. . .
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean silent = settings.getBoolean("silentMode", false);
setSilent(silent);
}
@Override
protected void onStop(){
super.onStop();
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", mSilentMode);
// Commit the edits!
editor.commit();
}
}
and read this link adviced me before. How can I refresh MediaStore on Android?
but i cant use these informations. i need more.
Edit 2: Hi. I dont think saving my objects in SharedPrefrences solves my problem. becuse when an audio that created by my app make changes(name changing for example) then when app runs,that dosnt know variations.and i suppose my app cant perform these variations in my list yet. isnt true?? I write this code but when I record an audio and save its name with prefrences and i exit from app and i change my audio,s name and run my program again my audio,s name must be change in textview.but show "null" just. i think using of sharedPrefrences dosnt solve my issue.
` import android.app.Activity;
import android.content.SharedPreferences; import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class TestSharedActivity extends Activity {
Button btnst=null;
Button btnsp=null;
AudioRecorder myAudio=null;
TextView tv=null;
String audioName=null;
public static final String PREFS_NAME = "MyPrefsFile";
protected void onCreate(Bundle state)
{
super.onCreate(state);
setContentView(R.layout.main);
btnst=(Button) findViewById(R.id.btnrec);
btnsp=(Button) findViewById(R.id.btnstop);
tv=(TextView) findViewById(R.id.textv);
onTouchListeners();
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
// boolean silent = settings.getBoolean("silentMode", false);
String name = settings.getString("mname","null");
setName(name);
}
private void setName(String name)
{
tv.setText(name);
}
@Override
protected void onStop()
{
super.onStop();
// We need an Editor object to make preference changes.
// All objects are from android.context.Context
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("mname", audioName);
// Commit the edits!
editor.commit();
}
/////////////////////////
private void onTouchListeners()
{
View.OnTouchListener startListener=new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (MotionEvent.ACTION_DOWN == event.getAction())
{
}
else if (MotionEvent.ACTION_UP == event.getAction())
{
myAudio=new AudioRecorder();
audioName=myAudio.getName();
String path=myAudio.getPath();
tv.setText(path);
try
{
myAudio.Record();
}
catch(Exception e)
{
Log.d("audio recorddddddddd","cant starttt!!!!!!!!!!!!");
}
}
return true;
}
};
////////////////////////////////////////////////
View.OnTouchListener stopListener=new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (MotionEvent.ACTION_DOWN == event.getAction())
{
}
else if (MotionEvent.ACTION_UP == event.getAction())
{
try
{
myAudio.stopRecord();
}
catch(Exception e)
{
Log.d("audio record stoppppppppppp",e.toString());
}
}
return true;
}
};
btnst.setOnTouchListener(startListener);
btnsp.setOnTouchListener(stopListener);
}//end ontouch
} ` AudioRecorder is an class for record and save audios to my special folder on SDcard. and main.xml have 2 button "record and stop" and a textview for show name my audio and when run again it shows changed audio,s name.(if it take changes)