• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to set ringtone.

GHZDev

Lurker
Hi guys I tried to set the ringtone from an appilcation but the application crash.

This is the code:

Code:
@Override
    public void onClick(View v) {
        //I set the uri variable to the resource folder and for each positoin I set a difference quotes res id.
        Uri uri = Uri.parse("android.resource://com.ghzncl.barneystinsonsoundboard/"+R.raw.single]);
        
        RingtoneManager.setActualDefaultRingtoneUri(mContext, RingtoneManager.TYPE_NOTIFICATION, uri);

        //I set the data source of the mPlayer. I pass to the method the context and the uri of the resource.
        try{
            //I reset the mPlayer to its uninitialized state, in this way I don't need to stop the previews running quotes. 
            mPlayer.reset();
            mPlayer.setDataSource(mContext,uri);
        }catch(Exception e){}
        try{
            mPlayer.prepare();
        }catch(Exception e){}
        
        //The quotes start
        mPlayer.start();
        
    }

How can I solve this? Thanks.
 
Ok, It doesn't crash anymore because I added the permission but even if I doesn't crash I get a problem, the Ringtone doesn't change... Why??
 
Back
Top Bottom