【问题标题】:Monitor Notification from other apps监控来自其他应用程序的通知
【发布时间】:2014-08-02 08:33:15
【问题描述】:

我正在开发一款 android 应用程序,该应用程序可以收听来自其他应用程序(如 gmail)的通知并将它们累积在一个位置,或者根据其他应用程序生成的通知生成自己的自定义通知。一个类似的应用程序是地铁通知。以下是此应用的链接:

https://play.google.com/store/apps/details?id=com.nlucas.wp7notifications&hl=en

此应用能够阻止其他应用的通知并生成自己的自定义通知。我想知道这怎么可能。应用程序如何能够监控来自其他应用程序的通知。我用谷歌搜索了同样的东西,但我找不到任何解决方案。

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    您可以扩展 NotificationListenerService 并覆盖 onNotificationPosted 方法

     @Override
        public void onNotificationPosted(StatusBarNotification sbn) {
                Log.i(TAG, "onNotificationPosted");
                Log.i(TAG, "ID :" + sbn.getId() + "\t" + sbn.getNotification().tickerText + "\t" + sbn.getPackageName());
    
        }
    

    您还需要在清单中声明您的服务

        <service android:name="yourpackage.yourservice"
            android:label="@string/app_name"
            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
            <intent-filter>
                <action android:name="android.service.notification.NotificationListenerService" />
            </intent-filter>
        </service>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多