5

このアプリケーションを adnroid デバイスで実行しています。私は WhatsApp 通知に反応し (他の方法を知らないため)、アプリケーションが新しいメッセージについてユーザーに通知するようにする必要があります。私たちのユーザーは障害のある人なので、もう少しシンプルなインターフェースを提供する必要があります。通知を受け取るために、「com.whatsapp」パッケージ フィルターを使用してアクセシビリティ サービスを作成しました。アプリケーションを再インストールするまで、すべてがうまく機能します。再インストール後、サービスを手動で再度バインドする必要があります (これは非常に問題です)。どんな助けでも大歓迎です!

これは「onAccessibilityEvent」コードです:

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {

    Log.d(TAG, "NotificationService event");

    if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {

        String packageName = event.getPackageName().toString();

        if(packageName.equals("com.whatsapp")){
            // do some logic;
        }

// Utils.showLargeToast(getApplicationContext(), "新しい WhatsApp メッセージ"); } }

accessibilty_service_config

android:packageNames="@null"
android:accessibilityEventTypes="typeNotificationStateChanged"
android:accessibilityFlags="flagDefault"
android:accessibilityFeedbackType="feedbackGeneric"
android:notificationTimeout="100"
android:canRetrieveWindowContent="false"
android:description="@string/description_that_shows_on_the_accessibility_page" />

マニフェスト部

     android:name=".NotificationService"
        android:enabled="true"
        android:exported="false"
        android:label="WhatsApp Monitor Service">

        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>

        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/accessibility_service_config" />

前もって感謝します!

4

0 に答える 0