-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added READ_CONTACTS permission to be able to access accounts #351
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,7 @@ Licensed to the Apache Software Foundation (ASF) under one | |
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static android.Manifest.permission.GET_ACCOUNTS; | ||
import static android.Manifest.permission.READ_EXTERNAL_STORAGE; | ||
import static android.Manifest.permission.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not that versed in Android Java, but it is wise to import |
||
import static android.content.pm.PackageManager.PERMISSION_GRANTED; | ||
|
||
@SuppressWarnings({"Convert2Diamond", "Convert2Lambda"}) | ||
|
@@ -185,41 +184,51 @@ public void run() { | |
* | ||
* @param code The code number of the permission to check for. | ||
*/ | ||
private void check(int code) { | ||
check(getPermission(code)); | ||
private void check(int code){ | ||
check(getPermissions(code)); | ||
} | ||
|
||
/** | ||
* Check if the given permission has been granted. | ||
* Check if the given permissions have been granted. | ||
* | ||
* @param permission The permission to check for. | ||
* @param permissions The permissions to check for. | ||
*/ | ||
private void check(String permission) { | ||
Boolean granted = cordova.hasPermission(permission); | ||
sendResult(new PluginResult(Status.OK, granted)); | ||
private void check(String... permissions){ | ||
for (int i = 0; i < permissions.length; i++) | ||
{ | ||
if (!cordova.hasPermission(permissions[i])) | ||
{ | ||
sendResult(new PluginResult(Status.OK, false)); | ||
return; | ||
} | ||
} | ||
sendResult(new PluginResult(Status.OK, true)); | ||
} | ||
|
||
/** | ||
* Request given permission. | ||
* | ||
* @param code The code number of the permission to request for. | ||
*/ | ||
private void request(int code) { | ||
cordova.requestPermission(this, code, getPermission(code)); | ||
private void request(int code){ | ||
cordova.requestPermissions(this, code, getPermissions(code)); | ||
} | ||
|
||
/** | ||
* Returns the corresponding permission for the internal code. | ||
* Returns the corresponding permissions for the internal code. | ||
* | ||
* @param code The internal code number. | ||
* | ||
* @return The Android permission string or "". | ||
* @return Array of the the Android permission strings or []. | ||
*/ | ||
private String getPermission(int code) { | ||
switch (code) { | ||
case 1: return READ_EXTERNAL_STORAGE; | ||
case 2: return GET_ACCOUNTS; | ||
default: return ""; | ||
private String[] getPermissions(int code){ | ||
switch (code) | ||
{ | ||
case 1: | ||
return new String[]{READ_EXTERNAL_STORAGE}; | ||
case 2: | ||
return new String[]{GET_ACCOUNTS, READ_CONTACTS}; // see https://stackoverflow.com/a/54941079/4094951 | ||
default: | ||
return new String[0]; | ||
} | ||
} | ||
|
||
|
@@ -261,14 +270,11 @@ public void onActivityResult(int reqCode, int resCode, Intent intent) { | |
*/ | ||
@Override | ||
public void onRequestPermissionResult(int code, String[] permissions, | ||
int[] grantResults) { | ||
|
||
int[] grantResults){ | ||
List<PluginResult> messages = new ArrayList<PluginResult>(); | ||
Boolean granted = false; | ||
|
||
if (grantResults.length > 0) { | ||
granted = grantResults[0] == PERMISSION_GRANTED; | ||
} | ||
boolean granted = true; | ||
for (int i = 0; i < grantResults.length; i++) | ||
granted = granted && (grantResults[i] == PERMISSION_GRANTED); | ||
|
||
messages.add(new PluginResult(Status.OK, granted)); | ||
messages.add(new PluginResult(Status.OK, code)); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 breaking the build when I insert this in
config.xml
, did you meanedit-config
instead?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 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 could make it work, it was missing
xmlns:android="http://schemas.android.com/apk/res/android"
at thewidget
root ofconfig.xml