-1

Android Things only support limited number of API such Cast, Drive, and Location APIs. I'm trying to work with one API and I want to map between the API methods and its required permission. I'm not sure what is the best approach to do such a task. I'm working with Intel Edison board. Basically, I need to do something like this:

====== Method ============= Required Android Permission =============

=====getLocation()====>===== android.permission.ACCESS_FINE_LOCATION

=====getBeaconState()===>===== android.permission.ACCESS_FINE_LOCATION

Also, I need to see what happens if the permission required is missing? I'm just looking for thoughts on how to do these tasks.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Timmy
  • 107
  • 4
  • 18
  • you have to check ACCESS_FINE_LOCATION every time you are trying to work with map (load, getLocation, e.t.c.). Sometimes Studio will mark you that part of your code where you have to place if(*check permission*) condition. If permission dosen't exist you must call requestPermissions. – shagi Apr 14 '17 at 06:39
  • But this is not the case with Android Things right? Also, with android M in general, how the app acts when it tries to find a permission that is not exist? – Timmy Apr 19 '17 at 03:56

4 Answers4

1

I'm not sure what you are trying to achieve, if it is documentation or something in code, but fwiw AndroidThings act's differently for permissions, so you don't have to do anything in your codebase.

Requesting Permissions at Runtime is not supported because embedded devices aren't guaranteed to have a UI to accept the runtime dialog. Declare permissions that you need in your app's manifest file. All normal and dangerous permissions declared in your app's manifest are granted at install time.

This is from the Android Things docs https://developer.android.com/things/sdk/index.html

As you can see it says

All normal and dangerous permissions declared in your app's manifest are granted at install time.

Therefore if you use maps that requires ACCESS_FINE_LOCATION you will be granted the permission at install time and will not need to code anything for "runtime permissions" as they do not exist.

Blundell
  • 75,855
  • 30
  • 208
  • 233
  • Yes, I'm looking for some sort of documentation that list all AT supported API along with the required permissions. what I wanted is something similar to this http://pscout.csl.toronto.edu/. – Timmy Apr 19 '17 at 03:54
  • 1
    all the api's not supported are written on this page: https://developer.android.com/things/sdk/index.html i.e. content providers & google play services features that require UI. The list of "required" permissions will be roughly similar to stock Android – Blundell Apr 19 '17 at 06:42
0

Try this for location runtime permission

if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) ==
                PackageManager.PERMISSION_GRANTED &&
                ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) ==
                        PackageManager.PERMISSION_GRANTED) {

         //Do your work if permission already granted

        } else {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
        }

and override onRequestPermissionResult

@Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if (requestCode == 1) {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

             //Do your Work
            }
        }
    }
AbhayBohra
  • 2,047
  • 24
  • 36
  • note that if you are using fragment v4 you can call *requestPermissions* without *ActivityCompat* or if v13 then *Fragment.requestPermissions* static method – shagi Apr 14 '17 at 06:49
0

Declare this in AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Install the apk on device, and then reboot the device, it fixed my issue.

Yasir
  • 1
  • 1
-1

Use ActivityCompat.checkSelfPermission for check permission.

Use ActivityCompat.requestPermissions for request permission.

Use interface ActivityCompat.OnRequestPermissionsResultCallback for callback.

yao liu
  • 121
  • 8