diff --git a/CHANGELOG.md b/CHANGELOG.md index 6720025..51b8edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Updated Portuguese (Brazil) translation thanks to APL ([@APL](https://hosted.weblate.org/user/APL/)). - Updated Croatian translation thanks to Milo Ivir (@milotype). +### Fixed + +- Fixed a startup crash on Android 11+ (introduced in [0.5.7](#057-2020-10-02)). + ## [0.5.11] - 2020-11-08 diff --git a/app/src/main/java/dummydomain/yetanothercallblocker/data/CallLogHelper.java b/app/src/main/java/dummydomain/yetanothercallblocker/data/CallLogHelper.java index 86aa222..a3ad8b2 100644 --- a/app/src/main/java/dummydomain/yetanothercallblocker/data/CallLogHelper.java +++ b/app/src/main/java/dummydomain/yetanothercallblocker/data/CallLogHelper.java @@ -2,6 +2,8 @@ package dummydomain.yetanothercallblocker.data; import android.content.Context; import android.database.Cursor; +import android.net.Uri; +import android.os.Build; import android.provider.CallLog; import java.util.ArrayList; @@ -40,14 +42,23 @@ public class CallLogHelper { selectionArgs = null; } + Uri uri = CallLog.Calls.CONTENT_URI; + String sortOrder = CallLog.Calls.DATE + " " + (reverseOrder ? "ASC" : "DESC"); - sortOrder += " limit " + limit; + // should probably work since JELLY_BEAN_MR1 + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) { + uri = uri.buildUpon() + .appendQueryParameter(CallLog.Calls.LIMIT_PARAM_KEY, String.valueOf(limit)) + .build(); + } else { + sortOrder += " limit " + limit; + } List items = new ArrayList<>(limit); - try (Cursor cursor = context.getContentResolver().query(CallLog.Calls.CONTENT_URI, - QUERY_PROJECTION, selection, selectionArgs, sortOrder)) { + try (Cursor cursor = context.getContentResolver() + .query(uri, QUERY_PROJECTION, selection, selectionArgs, sortOrder)) { if (cursor != null) { int idIndex = cursor.getColumnIndex(CallLog.Calls._ID); int typeIndex = cursor.getColumnIndex(CallLog.Calls.TYPE);