我想安排一个每 1 分钟触发一次的闹钟并唤醒我的应用程序。它适用于模拟器,但不适用于定制的操作系统手机,如 VIVO、OPPO、MIUI 等。我编写了粘性服务和广播接收器。当服务将被销毁或 TaskRemoved 时,我调用了名为 sendBroadcast() 的方法,该方法将触发我的广播接收器,而我的 Brodcast 接收器将通过调用 startservice(intent) 方法再次启动服务。但这在应用程序被杀死时不起作用。当应用程序在前台时它工作正常。我希望警报管理器在应用程序被杀死时能够工作。
这是我下面的代码--
我的 MainActivity.java 文件启动服务--
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent alarmIntent = new Intent(this, AlarmService.class);
startService(alarmIntent);
} }
Run Code Online (Sandbox Code Playgroud)
我的粘性服务代码是——
public class AlarmService extends Service
{
private String TAG ="AlarmService";
@Override
public void onCreate()
{
sendBroadcast();
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
Log.e(TAG, "onStartCommand");
//return super.onStartCommand(intent, flags, startId);
return Service.START_STICKY;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我已经在我的 Android 应用程序中实现了 FCM 推送通知。我在数据负载中获取了所有通知 JSON。我在 api 上“未添加”“通知”标签。因此,在所有状态(前台/后台/已杀死)中,我仅在数据有效负载中收到通知。
当应用程序处于前台/后台/终止状态时,它在所有州的 Moto、Google 等非定制操作系统手机上都能正常工作。但问题是,当我在Oppo、Vivo或MIUI等定制操作系统手机上进行测试时,只有当应用程序位于前台或后台(应用程序在内存中)时,通知才会到达,而当应用程序被“杀死”时,通知不会到达/出现(不是在记忆中)。
我应该怎么办?
无论如何,感谢您抽出时间。
public class MyFirebaseMessagingService extends FirebaseMessagingService{
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// [START_EXCLUDE]
// There are two types of messages data messages and notification messages. Data messages are handled
// …Run Code Online (Sandbox Code Playgroud) java android push-notification firebase firebase-cloud-messaging