REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 触发但没有提示

REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Firing but No Prompt

我正在尝试在 Android 9 上使用 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS 在应用程序启动时的推送通知中禁用电池优化。

在 activity 文件中(使用通知生成器):

Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, 0);
NotificationCompat.Builder...
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getContext());
notificationManager.notify(notificationId, builder.build());

AndroidManifest.xml中:

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

我能够显示推送通知,但是当您点击时,它就消失了。 'Allow' 的提示没有弹出。我是不是设置有误?

您缺少数据中的 Uri。来自 documentation:

Input: The Intent's data URI must specify the application package name to be shown, with the "package" scheme. That is "package:com.my.app".

做类似的事情:

Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parseString("package:my.package.name");