Android 如何在自动停止后触发绑定\u通知\u侦听器\u服务
我正在做一个React原生应用程序(但我的问题主要与Android有关),我将在原生Android代码中捕获通知,然后通过回调将捕获的数据提供给Javascript 我正在使用Android 如何在自动停止后触发绑定\u通知\u侦听器\u服务,android,Android,我正在做一个React原生应用程序(但我的问题主要与Android有关),我将在原生Android代码中捕获通知,然后通过回调将捕获的数据提供给Javascript 我正在使用BIND\u NOTIFICATION\u LISTENER\u服务并在清单文件中为其指定了一个类NotificationListenerService AndroidManifest.xml 这里,我不是手动触发NotificationListenerService。我希望在Manifest中指定它可以让Androi
BIND\u NOTIFICATION\u LISTENER\u服务
并在清单
文件中为其指定了一个类NotificationListenerService
AndroidManifest.xml
这里,我不是手动触发
NotificationListenerService
。我希望在Manifest
中指定它可以让Android系统自动触发它
问题:
NotificationListenerService的onCreate
或onNotificationPosted
在安装2/3天后收到通知时未被调用
(我需要手动禁用/启用通知访问以使其重新工作)
我的期望:
在特定的时间间隔内触发服务,这样即使它被android系统停止,它也应该自动重新启动
如果我手动触发,我可以安排它在任何时间间隔内触发,但由于它是由Android自动触发的,我找不到(或我不知道如何)在特定时间间隔内执行触发操作
请用正确的路径指导我,以实现预期的行为
谢谢,我们将感谢您的时间和帮助。。。。(:你找到解决方案了吗?@Ganeshduplicate of@SamanSattari不是一个副本,因为他们解决的问题是,只有在更新应用程序(或在开发模式下重新编译应用程序)时,服务才起作用。我的问题是,问题发生在第一次安装本身。
<service
android:name=".NotificationListener"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"
android:enabled="true">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
public class NotificationListener extends NotificationListenerService {
Context context;
private String TAG = this.getClass().getSimpleName();
@Override
public void onCreate() {
super.onCreate();
// this method is not getting executed after 2 or 3 days of installation
Log.d("KBTCHECK", "NotificationListener - onCreate");
context = getApplicationContext();
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
// this method is not getting executed after 2 or 3 days of installation
Log.d("KBTCHECK", "NotificationListener - onNotificationPosted");
// My Logic here..
Intent msgrcv = new Intent("NOTIFICATION_POSTED_KBT");
msgrcv.putExtras(extras);
// Broadcasting it, so I'll capture in another module and send it to Javascript
LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv);
}
}