- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个 Activity 类需要获取设备当前的中断过滤器设置。
因此我有一个 MyNotificationListenerService
类,它派生自 NotificationListenerService 并实现了 onInterruptionFilterChanged()。
但是 onInterruptionFilterChanged()
仅在中断过滤器更改时被调用。当我的应用程序启动时,我需要找出中断过滤器的当前值是多少。 NotificationListenerService 有一个方法,它是 getCurrentInterruptionFilter()
。
我的问题是:MyActivity
如何在我的应用启动时调用 MyNotificationListenerService
的 getCurrentInterruptionFilter()
?
操作系统自动创建并启动 MyNotificationListenerService
,MyActivity
是否可以获取该对象的句柄以便调用 getCurrentInterruptionFilter()
明确地?如果不是,那么应该有什么通信机制才能让 MyActivity
能够从 MyNotificationListenerService
获取初始中断设置?
.
最佳答案
您想从您的 Activity 绑定(bind)到服务。 Android 文档在 http://developer.android.com/guide/components/bound-services.html 中对此进行了详细解释。
这是它如何工作的示例。
您的 Activity :
public class MyActivity extends Activity {
private MyNotificationListenerService mService;
private MyServiceConnection mServiceConnection;
...
protected void onStart() {
super.onStart();
Intent serviceIntent = new Intent(this, MyNotificationListenerService.class);
mServiceConnection = new MyServiceConnection();
bindService(serviceIntent, mServiceConnection, BIND_AUTO_CREATE);
}
protected void onStop() {
super.onStop();
unbindService(mServiceConnection);
}
private class MyServiceConnection implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName name, IBinder binder) {
mService = ((MyNotificationListenerService.NotificationBinder)binder).getService();
}
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
}
}
您的服务:
public class MyNotificationListenerService extends NotificationListenerService {
...
private NotificationBinder mBinder = new NotificationBinder();
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
public class NotificationBinder extends Binder {
public MyNotificationListenerService getService() {
return MyNotificationListenerService.this;
}
}
}
关于android - Activity 如何访问 NotificationListenerService 的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29169921/
我有一个 NotificationListenerService 和一个: @Override public void onNotificationPosted(StatusBarNotificati
NotificationListenerService可以用在android wear上吗? orb 是否有某种监听器可以监听可穿戴设备中的调用或通知? 最佳答案 通常我会做的是有一个电话和一个可穿戴
在扩展新的(SDK18,JB-4.3)NotificationListenerService 的服务中,我想获取通知的状态栏图标。 mStatusBarNotification.getNotifica
我在创建扩展 android.service.notification.NotificationListenerService 的服务时遇到问题 根据 https://developer.androi
在 android 4.4 中,我发现一些用户使用我实现的 notificationListenerService 将停止工作。我自己也亲眼见过。 我从来没有设法在它发生时捕捉到任何 logcat,但
我希望这不会违反任何规则,因为我已尝试遵循如何提问指南。 我正在尝试使用 NotificationListenerService 读取传入的通知,它对我有用,但只是部分有用。 它的第一个通知类型,比方
应用程序第一次因为一些错误而崩溃后,再次创建并绑定(bind)了 NLService,但是在第 2 次或第 3 次之后......,不再创建和绑定(bind) NLService,即使是复选框 设置
我正在尝试实现在 android 4.3 中添加的 NotificationListnerService,但我无法获取通知详细信息。 我的代码如下 public class MainActivity
随着 Android M 中 Doze 的引入,Android 在 Doze 期间对后台执行的限制越来越多。有人可以详细说明在扩展 Android 自己的服务时是否同样适用。比如Notificatio
我有一个派生自 NotificationListenerService 的类,它会在应用程序启动时自动为我创建和启动。但是,我想稍后从 Activity 中懒惰地启动该服务,而不是在应用程序启动时自动
我在我的 android 应用程序中从 Intentservice 启动前台服务,服务开始通知。这就是我开始服务的方式: Intent intent = new Intent(this, Naviga
我现在已经尝试了 10 多个小时,但我似乎无法考虑任何其他事情。我尝试了互联网上所有可能的示例,但没有成功。 我有扩展NotificationListenerService的NotificationM
我有一个 app还有一个 NotificationListenerService。当我在该 NotificationListenerService 中添加断点时,断点似乎停止了执行,但调试器无法识别它
我已经实现了 NotificationListenerService,但它不工作。这是服务: public class NotificationListener extends Notificatio
是否可以阅读在用户移动时定期显示的 Google map 导航通知? 例如,距离下一回合的剩余距离会定期更新。为此,我尝试使用 NotificationListenerService,但当我尝试使用
我会收听 WhatsApp 消息等通知。 但每次通知进入 NotificationListenerService 时都会触发两次。 有人知道这个问题吗?? 这是 AndroidManifest.xml
我在写 NotificationListenerService , 我想在其中获取发送到状态栏的通知的详细信息。 但我们唯一得到的是 Ticket text ,在某些情况下它是 null。 最佳答案
下面是我捕获通知的代码。我不明白为什么 onNotificationPosted 没有被解雇。 我正在通过“设置”>“安全”授予我的应用通知访问权限,MyNotifService 中的 onCreat
我有一个简单的 NotificationListenerService 实现来测试新的 4.3 API。该服务本身曾经工作过。之后,我添加了在添加特定包的通知时发送广播。现在,只要我启动该服务,它就会
我在对抗 NotificationListenerService 时运气不佳。我尝试了很多在这里和那里找到的食谱,尤其是关于……但它的效果很不一致。 先看代码: list :
我是一名优秀的程序员,十分优秀!