-
Notifications
You must be signed in to change notification settings - Fork 73
[MRG] Add the location permission for android 9. #286
[MRG] Add the location permission for android 9. #286
Conversation
skunkworks_crow/src/main/java/org/odk/share/views/ui/bluetooth/BtReceiverActivity.java
Outdated
Show resolved
Hide resolved
@@ -73,6 +75,11 @@ protected void onCreate(Bundle savedInstanceState) { | |||
setTitle(getString(R.string.send_instance_title)); | |||
setSupportActionBar(toolbar); | |||
|
|||
//checking the location permission for bluetooth for android 9. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to ask for this permission before opening the activity(When bluetooth option is choosen). Because both the permission asking dialog and scanning dialog appears at the same time .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we grant this permission when we are entering the main page? If we choose bluetooth then popup the permission dialog, that page still has the method choosing dialog appears at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we ask for location permission on start, then what if the user never chooses Bluetooth
as the transfer mode then it would not be of no use.
I'm suggesting to open a dialog asking for user permission when user taps on Bluetooth
as the transfer mode(Close the dialog asking for the mode of transfer then only show the dialog for the permission) and if user allows then send to BluetoothReceiver/Sender Screen otherwise again show the dialog saying that Location permission is needed for Bluetooth transfer
with two button options Cancel
(negative) and Access permission
(positive). Access permission
will ask user again for the permission and if he has selected the checkbox Never ask again
when permission was asked then you won't be able to request for permission again, in that case, you have to navigate user to our apps' settings so that he can manually go and give permission to us.
I know its pretty long process and but I think this is the way to tackle this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how generally other apps tackle this, in case you've some other option in mind please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I'll follow your suggestion. But can I use some run-time android permission library? So that I can remove the PermissionUtil.java
and make the code more flexible, something like https://github.com/Karumi/Dexter, it can also help me to build a dialog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, It totally depends on you what you want to use, and but don't forget to add it in our Open Source Licenses
section, its always to good to give the credits. And yes if you're doing it for Location permission then do it for every dangerous permission like read and write storage
. Or you can open a different PR for that.
@lakshyagupta21 I got a better idea, you can have a review of the code now. |
This also looks good to me. |
skunkworks_crow/src/main/java/org/odk/share/views/ui/bluetooth/BtSenderActivity.java
Outdated
Show resolved
Hide resolved
skunkworks_crow/src/main/java/org/odk/share/views/ui/bluetooth/BtSenderActivity.java
Outdated
Show resolved
Hide resolved
skunkworks_crow/src/main/java/org/odk/share/views/ui/bluetooth/BtSenderActivity.java
Outdated
Show resolved
Hide resolved
skunkworks_crow/src/main/java/org/odk/share/views/ui/bluetooth/BtReceiverActivity.java
Outdated
Show resolved
Hide resolved
@lakshyagupta21 thanks for your detailed review! I think the code is ready now. |
updated the open source license.
I think it's ready for a review @lakshyagupta21 . |
@huangyz0918 I just checked in android 6(Tablet) I am unable to send the forms it is exiting app automatically |
@Chromicle This PR is not related to android 6, can you work normally in master? |
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); | ||
Uri uri = Uri.fromParts(SCHEME, packageName, null); | ||
intent.setData(uri); | ||
targetActivity.startActivity(intent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an issue over here when the user moves to app settings, and no matter what he does there and after doing all the activity on app settings when he presses back he goes back to the Send data
screen with empty view.
You should check whenever an activity is resumed, whether user actually left application to actually play with the app settings, if the answer is yes then check if we've enough permission to do the transmission, if not then again display the same dialog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, I tested in android 9 and non-android 9 devices, no issues, but I think it still needs more tests.
@OnPermissionDenied({Manifest.permission.ACCESS_FINE_LOCATION, | ||
Manifest.permission.ACCESS_COARSE_LOCATION}) | ||
void showDeniedForLocation() { | ||
Toast.makeText(this, R.string.permission_location_denied, Toast.LENGTH_SHORT).show(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the toast length to LONG
, everywhere
I think we've to enable location permission for all device because in Android 7.1 I've to go and enable the location permission from the settings then only it starts showing the bluetooth devices when I start scanning it. |
So you mean I should remove the android 9 checks? |
Can you check this once in any of your Android 6 and Android 7 device, don't forget to check for location permission (verify when enabled/disabled) |
Ok, will do that and update this PR. |
You can checkout this, from Android 6, the |
I know that these permissions are required to be asked at runtime, but my doubt was why do we need to ask it I mean who requires this permission. |
I have done some tests on different devices using both real devices and virtual devices.
The conclusion is, in versions of Android prior to Marshmallow, the user could use Bluetooth without location services enabled, we need the location permission in all the devices with an API level > 6.0. @lakshyagupta21 |
Closes #284
What has been done to verify that this works as intended?
Tested in my Nexus 6P (android 9.0) with success.
Why is this the best possible solution? Were any other approaches considered?
This fix the android 9 permission issue with bluetooth, and after this issue was resolved, the bluetooth feature can work well in android 9 devices I think.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
N/A
Before submitting this PR, please make sure you have:
./gradlew checkCode
and confirmed all checks still pass OR confirm CircleCI build passes