android - How to get set the ringtone in notification -
i develop app user can set ringtone specified task
here's code appointment.class:
intent intent = new intent(ringtonemanager.action_ringtone_picker); intent.putextra(ringtonemanager.extra_ringtone_type, ringtonemanager.type_notification); intent.putextra(ringtonemanager.extra_ringtone_title, "select tone"); intent.putextra(ringtonemanager.extra_ringtone_existing_uri, (uri) null); this.startactivityforresult(intent, 5);
and activity extends broadcastreceiver
@override public void onreceive(context context, intent intent) { switch (getresultcode()){ case appointmentpage.result_ok: log.e("sample","asdas"); break; }
my problem dont see sample in logcat. how can see it?
you should use onactivityresults in activity user save preference , retrieve in onrecieve use
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); switch (requestcode) { case 5: { if (resultcode == result_ok ) { uri uri = data.getparcelableextra(ringtonemanager.extra_ringtone_picked_uri); if (uri != null) { sharedpreferences sharedpreference = getsharedpreferences("key_for_shared_preference",mode_private); sharedpreferences.editor editor = sharedpreference.edit(); editor.putstring("selected_ringtone_uri",uri.tostring()); editor.apply(); } break; } } } }
for work need fire intent same activity
intent intent = new intent(ringtonemanager.action_ringtone_picker); intent.putextra(ringtonemanager.extra_ringtone_type, ringtonemanager.type_notification); intent.putextra(ringtonemanager.extra_ringtone_title, "select tone"); intent.putextra(ringtonemanager.extra_ringtone_existing_uri, (uri) null); startactivityforresult(intent, 5);
and retrieve in broadcastreceiver in onreceive every time
@override public void onreceive(context context, intent intent) { sharedpreferences sharedpreference = getsharedpreferences("key_for_shared_preference",mode_private); string ringtoneuri = sharedpreference.getstring("selected_ringtone_uri",""); if(!ringtoneuri.contentequals("")){ log.d("ringtone uri",ringtoneuri); } }
Comments
Post a Comment