2017-05-07 45 views
0

Android Wear 2.0デバイスの「着信拒否」設定を管理するアプリケーションを作成したいと思います。下に貼り付けられたすべてのコードはAndroid搭載端末で正常に動作しています。電流遮断設定を読み込みandroid wearのACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS

は許可が必要です。電話やウェアラブル現在の状態に

<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" /> 

を使用して取得することができます。

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
int state = mNotificationManager.getCurrentInterruptionFilter(); 

状態は、このコードで設定できる着信拒否します

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY); 

これには、「着信拒否設定へのアクセス」が必要です。そうしないと、セキュリティ例外がスローされます。

java.lang.SecurityException: Notification policy access denied 

このパーミッションは、モバイルで構成アクティビティーを開始して要求することができます。ウェアラブルオン

Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); 
startActivity(intent); 

これは、例外が発生します。

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS } 

この手段この設定作業はウェアラブル設定では利用できません。この許可をアプリケーションに与える方法がありますか?

答えて

関連する問題