When using the ringtonemanager - like the example below - is there a way to check to see if the bounce.mp3 has already been added to the mediastore (without invoking ringtone picker)? I am setting the ringtone in the background from a list of possible MP3s, and what I notice is that the first time an MP3 is selected it works ok. If I choose the same MP3 from the list again - it raises a null pointer on the AddToMediaStore line.
B4X:
Dim r As RingtoneManager
Dim u As String
u = r.AddToMediaStore(File.DirRootExternal, "bounce.mp3", "Bounce!", True, True, True, True)
r.SetDefault(r.TYPE_RINGTONE, u)
Can you post the full error message from the logs?
I tested it and the Bounce! ringtone was successfully added multiple times.
With that said it is better to only add it once and save the Uri in a file.
Strange thing is - I just tested a prior version of what I was doing and I don't get any error. Other than a different mp3 name - the code is the same. Perhaps I went wrong elsewhere in my app that is impacting this now - it always works the first time selecting an MP3 and not the second. Attached is the log.
Why do you need to add the same ringtone again? You will just end up cluttering the ringtone list.
You should instead add it only on the first time your application runs and save the returned value in a file. Now you can read the Uri from the file and access the ringtone.
Hi Erel
I've the same error.
When I use Try Catch it is not success for setdefault ringtone.
======This is Error Log=====
B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_show_lis (java line: 597)
java.lang.NullPointerException
at anywheresoftware.b4a.phone.RingtoneManagerWrapper.AddToMediaStore(RingtoneManagerWrapper.java:93)
at b4a.example.main._show_lis(main.java:597)
at b4a.example.main._img_longclick(main.java:485)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$2.onLongClick(ViewWrapper.java:88)
at android.view.View.performLongClick(View.java:4276)
at android.view.View$CheckForLongPress.run(View.java:17731)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5457)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
=======Please===
This is my lesson project. There is no two files ("2myatnaryuu.ogg", "3yinkaung.ogg"). I deleted because I can't upload
========Help me please