Android Tutorial Runtime Permissions (Android 6.0+ Permissions)

Status
Not open for further replies.

scsjc

Well-Known Member
Licensed User
Longtime User
Hello, i'm trying the runtime on 6.0.1,
on this line : rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
get this error :


B4X:
LogCat connected to: 7091585a
--------- beginning of system
--------- beginning of main
** Service (starter) Create **
Error occurred on line: 26 (Starter)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
    at anywheresoftware.b4a.objects.RuntimePermissions.CheckAndRequest(RuntimePermissions.java:62)
    at myworldapp.people.com.starter._service_create(starter.java:267)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at myworldapp.people.com.starter.onCreate(starter.java:54)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3807)
    at android.app.ActivityThread.access$2100(ActivityThread.java:221)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1882)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7224)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Service (starter) Start **

can help me?
thanks!!!!
 

MarcoRome

Expert
Licensed User
Longtime User
I dont think that you can use this is a service. Try same code in Activity
 

M.LAZ

Active Member
Licensed User
Longtime User
- Once you've uploaded your app to Google Play with targetSdkVersion set to 23 you cannot downgrade the target version back.
that's what happend for me...i set it to 25 and coudn't downgrade it back..
so i used the Runtime Permissions for sdk > 23
every thing is ok now ,, my app works fine
but when i trying upload to google store give me this error message :

Upload failed
Duplicate declarations of permission android.permission.WRITE_EXTERNAL_STORAGE with different maxSdkVersions.

my manifest file :

 

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hi to all,
I have to manage the automatic positioning device with GPS library and I have to be able to activate the positioning enabled automatically with Runtime Permissions, from the application, and without the user's permission.

How can I do it?

Thank you
 

tracklocator

Member
Licensed User
Hello @Erel just started in the app development I am doing the map example and the fine location permissions. I have not had success already the point:

If <user has already approved> Or <older device> Then
Activity_PermissionResult (Permission, True)
Else
ShowDialog
Activity_PermissionsResult (Permission, Dialog result)
End If

The example code I use is as follows:

#Region Project Attributes
#ApplicationLabel: Maps Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#AdditionalJar: com.google.android.gmslay-services-maps

#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

'Activity module
Sub Process_Globals
Dim rp As RuntimePermissions
End Sub

Sub Globals
Private gmap As GoogleMap
Private MapFragment1 As MapFragment
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
If MapFragment1.IsGooglePlayServicesAvailable = False Then
ToastMessageShow("Please install Google Play Services.", True)
End If
End Sub

Sub MapFragment1_Ready
gmap = MapFragment1.GetMap
rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
Dim m1 As Marker = gmap.AddMarker(10, 30, "test")
m1.Snippet = "This is the snippet"
End Sub


Sub Activity_PermissionResult (Permission As String, Result As Boolean)
If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
If Result Then
gmap.MyLocationEnabled = Result
End If
End If
End Sub

'End of example code

The error I have is the following:


** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.RuntimeException: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:196)
at com.google.android.gms.maps.MapFragment$zza$1.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzt$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:387)
at zu.acom.google.android.gms.DynamiteModulesB:82)
at maps.ad.t$5.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
at maps.ad.t.c(Unknown Source)
at xj.onTransactcom.google.android.gms.DynamiteModulesB:274)
at android.os.Binder.transact(Binder.java:387)
at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.setMyLocationEnabled(Unknown Source)
at com.google.android.gms.maps.GoogleMap.setMyLocationEnabled(Unknown Source)
at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:183)
... 12 more

I have tried different ways but I still do not make it work.

I hope you can help me

Thanks for your time.
 

hanyelmehy

Active Member
Licensed User
Longtime User
i use targetSdkVersion=22 and add
B4X:
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.READ_EXTERNAL_STORAGE
when run app on android 6+ and use File.Copy to RootExternal i get Permission denied
 

hanyelmehy

Active Member
Licensed User
Longtime User
How did you add this permission?
Can you post your manifestcode from the manifesteditor please
i use
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
AddPermission("android.permission.READ_EXTERNAL_STORAGE")
 

DonManfred

Expert
Licensed User
Longtime User
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
AddPermission(
"android.permission.READ_EXTERNAL_STORAGE")
The Permissions are not Strings!

Use this permissions.
AddPermission(android.permission.READ_EXTERNAL_STORAGE) ' Allows an application to read from external storage.
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE) ' Allows an application to write to external storage.

See this list for all permissions
https://www.b4x.com/android/forum/threads/addpermission-a-list-of-permissions-in-android.39401/
 

DonManfred

Expert
Licensed User
Longtime User
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…