why can I save the rintong in URI with RingtoneManager.TYPE_RINGTONE? will permit problems?

0

Occupy

 Uri uriSoundDefault = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString("urime",uriSoundDefault.toString());
    editor.apply();

to put the default ring tone and if it works well when the rintong is selected by default from the internal list of the cel but when you put a persnonalized tone that is a downloaded mp3 or from another directory my app stops and I do not know how to have the call tone in URI either from the system or selected by the user, or that I need to add? permissions etc

public class llamada extends AppCompatActivity {

MediaPlayer musica;
public SharedPreferences prefs;
public ImageView contestar,colgar;
public Uri urim;
public String urimp3;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_llamada);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    prefs=getSharedPreferences("MisPreferencias",this.MODE_PRIVATE);
    try {
         urimp3 = prefs.getString("urime", null);

        if(urimp3==null)
        {
            musica=MediaPlayer.create(this,R.raw.mp3);
        }else{
           urim=Uri.parse(urimp3);
           musica=MediaPlayer.create(this,urim);}
    } catch (IllegalArgumentException e) {
         }
    musica.setLooping(true);
    musica.start();
    ImageView personaje = findViewById(R.id.persona);
    TextView nombre = findViewById(R.id.nombre);
    TextView numero = findViewById(R.id.numero);
    contestar=findViewById(R.id.contestar);
    colgar=findViewById(R.id.colgar);
    personaje.setImageResource(prefs.getInt("imagen",R.mipmap.gente));
    nombre.setText(prefs.getString("nombre","nonono"));
    numero.setText(prefs.getString("numero","0000"));
    Toast.makeText(this,urimp3,Toast.LENGTH_LONG).show();
    contestar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i=new Intent(llamada.this,llamadaencurso.class);
            startActivity(i);
        }
    });
    colgar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i=new Intent(llamada.this,llamada_terminda.class);
            startActivity(i);
        }
    });

}

@Override     protected void onDestroy () {         super.onDestroy ();         if (musica.isPlaying ()) {             music.stop ();             music.release ();         }     }

@Override
protected void onResume() {
    super.onResume();
    musica.start();
}

@Override
protected void onPause() {
    super.onPause();
    musica.pause();
}

}

and this comes out

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ramscore.simuladordellamadas, PID: 8028
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ramscore.simuladordellamadas/com.ramscore.simuladordellamadas.llamada}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2434)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494)
    at android.app.ActivityThread.access$900(ActivityThread.java:157)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5551)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference
    at com.ramscore.simuladordellamadas.llamada.onCreate(llamada.java:44)
    at android.app.Activity.performCreate(Activity.java:6272)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2387)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2494) 
    at android.app.ActivityThread.access$900(ActivityThread.java:157) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5551) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620
    
asked by Jose Luis Flamenco Chie 11.11.2018 в 01:33
source

0 answers