public void onRingtone(View view) {
final Uri currentTone= RingtoneManager.getActualDefaultRingtoneUri(Setting.this, RingtoneManager.TYPE_ALARM);
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Ringtone");
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentTone);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
startActivityForResult(intent, 999);
}
I have this onClick
method to select available Ringtone from it's own device.
When startActivityForResult()
method is called it redirects to custom popup dialog from where user can select a Ringtone and at same time it starts that Ringtone.
That's Ok.
But I want to save that Ringtone to play it on another activity.
So what should I do?
Can I store it in database(SQLite), or in SharedPreference or any other way?
Edit: I don't know why my question got closed even if I provided all information. But still giving more information, to understand my question better.
Xml file:
<RelativeLayout
android:id="@+id/Ringtone"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@id/sp2"
android:layout_marginTop="1dp"
android:background="@drawable/pressed"
android:clickable="true"
android:focusable="true"
android:onClick="onRingtone"
android:gravity="center"
android:paddingTop="15dp"
android:paddingBottom="15dp">
The above method is called when the user selects the Ringtone. I got one answer which told me to use SharedPreference to store uri. I want to keep the selected ringtone even after app gets closed. So SharedPreference is a better option but how to make it global so other activity can also use it?
If I create object of SharedPreference in this java file, how can I get access to other acivity?