hicaltech87
Member
I'm in update my apps to compatible in android 13
the problem is when i follow this notification permission https://www.b4x.com/android/forum/threads/notifications-permission-with-targetsdkversion-33.148233/
The apps become crash when i click on that menu
is my code is correct?
the problem is when i follow this notification permission https://www.b4x.com/android/forum/threads/notifications-permission-with-targetsdkversion-33.148233/
The apps become crash when i click on that menu
is my code is correct?
B4X:
Dim filedir As String = mainmenu.rp.GetSafeDirDefaultExternal("data")
mainmenu.rp.CheckAndRequest(mainmenu.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For (CheckAndRequestNotificationPermission) Complete (Result As Boolean)
If Result Then
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo("Permission", "App Need Your Permission to Save Database.", Me) 'Change Main to "" if this code is in the main module.
n.Notify(1)
If File.Exists(filedir,mainmenu.filedb) = False Then
File.Copy(File.DirAssets,mainmenu.filedb,filedir,mainmenu.filedb)
End If
mainmenu.sql.Initialize(filedir,mainmenu.filedb,True)
End If
setedittext
End Sub
Private Sub CheckAndRequestNotificationPermission As ResumableSub
Dim ps As Phone
If ps.SdkVersion < 33 Then Return True
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim targetSdkVersion As Int = ctxt.RunMethodJO("getApplicationInfo", Null).GetField("targetSdkVersion")
If targetSdkVersion < 33 Then Return True
Dim NotificationsManager As JavaObject = ctxt.RunMethod("getSystemService", Array("notification"))
Dim NotificationsEnabled As Boolean = NotificationsManager.RunMethod("areNotificationsEnabled", Null)
If NotificationsEnabled Then Return True
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_POST_NOTIFICATIONS)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean) 'change to Activity_PermissionResult if non-B4XPages.
Log(Permission & ": " & Result)
Return Result
End Sub