他のアプリケーションによって通知バーで発生した通知を読み取り/アクセス/ログに記録したいと考えています。
Intents
色々と調べPendingIntents
たのですが、解決に至りませんでした。
通知が発生した場合、アプリケーションに通知する必要がありますか?
または、Android システムは、ユーザーレベルのアプリケーションによる通知を読み取るための何かを提供していますか?
他のアプリケーションによって通知バーで発生した通知を読み取り/アクセス/ログに記録したいと考えています。
Intents
色々と調べPendingIntents
たのですが、解決に至りませんでした。
通知が発生した場合、アプリケーションに通知する必要がありますか?
または、Android システムは、ユーザーレベルのアプリケーションによる通知を読み取るための何かを提供していますか?
API 18 (android 4.3) 以降では可能です: http://developer.android.com/reference/android/service/notification/NotificationListenerService.html
使い方はとても簡単ですが、ユーザーはアプリに手動で許可を与える必要があります。
ついに答えを得た.!!! アクセシビリティ サービスの使用
public class NotificationService extends AccessibilityService {
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
// TODO Auto-generated method stub.
//Code when the event is caught
}
@Override
public void onInterrupt() {
// TODO Auto-generated method stub.
}
@Override
protected void onServiceConnected() {
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.feedbackType = 1;
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.notificationTimeout = 100;
setServiceInfo(info);
}
}
そして私のマニフェストは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.test.notify"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<service android:name=".NotificationService" android:enabled="true">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
</service>
</application>
</manifest>
コーディングをお楽しみください!!! :)
通知にアクセスするための API はありません。少なくともそれはセキュリティの穴になるでしょう。できることは、通知 (SMS など) を引き起こすいくつかのイベントをキャッチすることだけです。
ANotification
は、 を送信することによって発生しIntent
ます。
Intent intent = new Intent(this, NotificationReceiver.class);
NotificationReceiver
が をキャッチし、をIntent
ポップアップしNotification
ます。
BroadCastReceiverIntent
を使用してアプリケーションの 1 つで同じものをキャッチし、必要に応じてフィルター処理することは完全に可能です。Intent