does the URI id change when the app is restarted?

0

I select the file in mp3 to save it in shared preferences and while it does not close the app the song sounds and everything, when restarting the app as it throws error and it does not sound anything, that the id that points to arhivo with URI, is change when restarting the app or what am I doing wrong ??? XC

  

Here you select an audio for ring tone inside the app "false call" and save in shared preferences

public void elijemp3(View view){
    Intent intent = new Intent();
    intent.setType("audio/mp3");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Open Audio (mp3) file"), 1);

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1 && resultCode == Activity.RESULT_OK){
        if ((data != null) && (data.getData() != null)){
            Uri audioFileUri = data.getData();
            //Toast.makeText(this,"hihihi",Toast.LENGTH_LONG).show();
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("urime", audioFileUri.toString());
            editor.apply();
        }
    }
    Intent i=new Intent(this,MainActivity.class);
    startActivity(i);
}
  

here the activity of the app is launched simulating the call and puts it as a tone what is in shared preferences

prefs=getSharedPreferences("MisPreferencias",this.MODE_PRIVATE);
    urimp3 = prefs.getString("urime",null);
    if(urimp3==null)
    {
        urim=Uri.parse("android.resource://"+getPackageName()+"/raw/mp3");
    }
    else{
        urim=Uri.parse(urimp3);
    }
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString("urime",urim.toString());
    editor.apply();
    mPlayer = new MediaPlayer();
    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {
        mPlayer.setDataSource(getApplicationContext(), urim);
    } catch (IllegalArgumentException e) {
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
    } catch (SecurityException e) {
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
    } catch (IllegalStateException e) {
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        mPlayer.prepare();
    } catch (IllegalStateException e) {
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
    }
    mPlayer.setLooping(true);
    
asked by Jose Luis Flamenco Chie 02.11.2018 в 03:38
source

0 answers