-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): Expose api to handle Android 12 REQUIRE_EXACT_ALARM pe…
…rmission (#332)
- Loading branch information
1 parent
421faff
commit f9dbf21
Showing
16 changed files
with
325 additions
and
151 deletions.
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
19 changes: 19 additions & 0 deletions
19
android/src/main/java/app/notifee/core/AlarmPermissionBroadcastReceiver.java
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.notifee.core; | ||
|
||
import static android.app.AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.util.Log; | ||
|
||
public class AlarmPermissionBroadcastReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
|
||
if (intent.getAction().equals(ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED)) { | ||
Log.i("AlarmPermissionReceiver", "Received alarm permission state changed event"); | ||
new NotifeeAlarmManager().rescheduleNotifications(); | ||
} | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
android/src/main/java/app/notifee/core/utility/AlarmUtils.java
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package app.notifee.core.utility; | ||
|
||
import static app.notifee.core.ContextHolder.getApplicationContext; | ||
|
||
import android.app.Activity; | ||
import android.app.AlarmManager; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.provider.Settings; | ||
import app.notifee.core.ContextHolder; | ||
import app.notifee.core.Logger; | ||
|
||
public class AlarmUtils { | ||
private static final String TAG = "AlarmUtils"; | ||
|
||
public static AlarmManager getAlarmManager() { | ||
return (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); | ||
} | ||
|
||
/** | ||
* Attempts to open the device's alarm special access settings | ||
* | ||
* @param activity | ||
*/ | ||
public static void openAlarmPermissionSettings(Activity activity) { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { | ||
return; | ||
} | ||
|
||
try { | ||
Intent intent = new Intent(); | ||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
intent.setAction(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM); | ||
Context context = ContextHolder.getApplicationContext(); | ||
String packageName = context.getPackageName(); | ||
intent.setData(Uri.parse("package:" + packageName)); | ||
|
||
IntentUtils.startActivityOnUiThread(activity, intent); | ||
} catch (Exception e) { | ||
Logger.e(TAG, "An error occurred whilst trying to open alarm permission settings", e); | ||
} | ||
} | ||
|
||
public static boolean canScheduleExactAlarms() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
return getAlarmManager().canScheduleExactAlarms(); | ||
} | ||
return true; | ||
} | ||
} |
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
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
Oops, something went wrong.