Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Check android version before calling permission API. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public void onMethodCall(MethodCall call, Result result) {
case "getPhoneLogs":
String startDate = call.argument("startDate");
String duration = call.argument("duration");
fetchCallRecords(startDate, duration);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
noAuthFetchCallRecords(startDate, duration);
} else {
fetchCallRecords(startDate, duration);
}
break;
default:
result.notImplemented();
Expand Down Expand Up @@ -102,10 +106,7 @@ public boolean onRequestPermissionsResult(int requestCode, String[] strings, int
CallLog.Calls.DURATION,
};

@TargetApi(Build.VERSION_CODES.M)
private void fetchCallRecords(String startDate, String duration) {
if (registrar.activity().checkSelfPermission(Manifest.permission.READ_CALL_LOG)
== PackageManager.PERMISSION_GRANTED) {
private void noAuthFetchCallRecords(String startDate, String duration) {
String selectionCondition = null;
if (startDate != null) {
selectionCondition = CallLog.Calls.DATE + "> " + startDate;
Expand Down Expand Up @@ -142,7 +143,13 @@ private void fetchCallRecords(String startDate, String duration) {
cursor.close();
}
}
}

@TargetApi(Build.VERSION_CODES.M)
private void fetchCallRecords(String startDate, String duration) {
if (registrar.activity().checkSelfPermission(Manifest.permission.READ_CALL_LOG)
== PackageManager.PERMISSION_GRANTED) {
noAuthFetchCallRecords(startDate, duration);
} else {
pendingResult.error("PhoneLog", "Permission is not granted", null);
pendingResult = null;
Expand Down