0

I already have the right things to play audio files from RAW, and fool around with it but, here is what I want to do: I want to enable the user to select audio from sdcard. and choose that so the app play it for him. I have :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>

then in preferences: I have:

        <Preference
        android:title="Pick file"
        android:key="filePicker"  />

and then in ShowPreferenceActivity I have:

 Preference filePicker = (Preference) findPreference("filePicker");
     filePicker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
         @Override
         public boolean onPreferenceClick(Preference preference) {
             //Intent intent = new Intent("org.openintents.action.PICK_FILE"); //Intent to start openIntents File Manager
             //startActivityForResult(intent, 1);
             Log.v("filePicker:", "filePicker got CLICKED");
             Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("Audio/mp3");
                startActivityForResult(intent, 1);
             return true;

and also:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//get the new value from Intent data

String newValue = "";
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("filePicker", newValue);
Log.v("filePicker:RESULT:", newValue);
editor.commit();

Im sure the problem lays here, because the log.v never gets called. so wherever I try:

 SharedPreferences sharedPrefs = PreferenceManager
         .getDefaultSharedPreferences(this);
 String changedRINGTONE=sharedPrefs.getString("filepicker", "NULL");

changedRINGTONE is null. and not the NULL (with the uppercase) I passed in getString, as it is really null! pardon my novice information, any guide is highly appreciated.

Shervin4030
  • 27
  • 1
  • 9
  • your newValue string is never changed ... it is always a default value since the time it is declared. So when you editor.putString("filePicker", newValue); ... "" i.e.empty string is written in sharedprederences. – Rajen Raiyarela Sep 05 '14 at 11:28
  • @RajenRaiyarela thanks for the reply, I know what you say, but why the log in same next line is not my logcat ? so it is not called. am I wrong on this? – Shervin4030 Sep 05 '14 at 11:31
  • Try to replace `intent.setType("Audio/mp3");` with `intent.setDataAndType("Audio/mp3");`. Also, in your `onActivityResult`, do you get the same `requestCode` that you use in `startActivityForResult` ? read the `Intent data`, is there anything in it ? – nightfixed Sep 05 '14 at 11:44
  • @nightfixed I did, no luck at all. – Shervin4030 Sep 05 '14 at 11:54
  • do you mean to say when you call startActivityForResult, onActivityResult should be called? Then it will not. onActivityResult is called after user has done selection from the activity displayed on call of startActivityForResult and that activity set result. – Rajen Raiyarela Sep 05 '14 at 11:56
  • @RajenRaiyarela dear Rajen, I do select an audio everytime and expect to see the log at least. but nothing at all happens. – Shervin4030 Sep 05 '14 at 11:57

0 Answers0