diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..4c09168 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index f0ffbf1..b0dbc4e 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@ - + diff --git a/mobile/src/main/AndroidManifest.xml b/mobile/src/main/AndroidManifest.xml index d63a6a1..16e9cef 100644 --- a/mobile/src/main/AndroidManifest.xml +++ b/mobile/src/main/AndroidManifest.xml @@ -29,12 +29,16 @@ - - - - - - + + + + + + + diff --git a/mobile/src/main/ic_launcher-playstore.png b/mobile/src/main/ic_launcher-playstore.png index 31fcc5b..05ab18e 100644 Binary files a/mobile/src/main/ic_launcher-playstore.png and b/mobile/src/main/ic_launcher-playstore.png differ diff --git a/mobile/src/main/java/de/rhaeus/dndsync/DNDSyncListenerService.java b/mobile/src/main/java/de/rhaeus/dndsync/DNDSyncListenerService.java new file mode 100644 index 0000000..df9525b --- /dev/null +++ b/mobile/src/main/java/de/rhaeus/dndsync/DNDSyncListenerService.java @@ -0,0 +1,70 @@ +package de.rhaeus.dndsync; + +import android.app.NotificationManager; +import android.content.Context; +import android.os.Handler; +import android.os.PowerManager; +import android.os.VibrationEffect; +import android.os.Vibrator; +import android.util.Log; +import android.widget.Toast; + +import com.google.android.gms.wearable.MessageEvent; +import com.google.android.gms.wearable.WearableListenerService; + +public class DNDSyncListenerService extends WearableListenerService { + private static final String TAG = "DNDSyncListenerService"; + private static final String DND_SYNC_MESSAGE_PATH = "/wear-dnd-sync"; + + @Override + public void onMessageReceived (MessageEvent messageEvent) { + if (Log.isLoggable(TAG, Log.DEBUG)) { + Log.d(TAG, "onMessageReceived: " + messageEvent); + } + + if (messageEvent.getPath().equalsIgnoreCase(DND_SYNC_MESSAGE_PATH)) { + + byte[] data = messageEvent.getData(); + // data[0] contains if dnd or bedtime mode + // 0 = dnd + // 1 = bedtime mode + // data[1] contains dnd mode of phone + // 0 = INTERRUPTION_FILTER_UNKNOWN + // 1 = INTERRUPTION_FILTER_ALL (all notifications pass) + // 2 = INTERRUPTION_FILTER_PRIORITY + // 3 = INTERRUPTION_FILTER_NONE (no notification passes) + // 4 = INTERRUPTION_FILTER_ALARMS + byte mode = data[0]; + Log.d(TAG, "mode: " + mode); + byte dndStatePhone = data[1]; + Log.d(TAG, "dndStatePhone: " + dndStatePhone); + + // get dnd state + NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); +// if (!mNotificationManager.isNotificationPolicyAccessGranted()) { +// Toast.makeText(getApplicationContext(), "DNDSync missing DND permission!", Toast.LENGTH_SHORT).show(); +// Log.d(TAG, "DNDSync missing DND permission!"); +// } + + int filterState = mNotificationManager.getCurrentInterruptionFilter(); + if (filterState < 0 || filterState > 4) { + Log.d(TAG, "DNDSync weird current dnd state: " + filterState); + } + byte currentDndState = (byte) filterState; + Log.d(TAG, "currentDndState: " + currentDndState); + + if (mode == 0) { //dnd + if (dndStatePhone != currentDndState) { + mNotificationManager.setInterruptionFilter(dndStatePhone); +// Toast.makeText(getApplicationContext(), "DND set to " + dndStatePhone, Toast.LENGTH_LONG).show(); + Log.d(TAG, "DND set to " + dndStatePhone); + } + } else { + Log.d(TAG, "DNDSync mode went wrong: " + mode); + } + } else { + super.onMessageReceived(messageEvent); + } + } + +} diff --git a/mobile/src/main/res/mipmap-hdpi/ic_launcher.png b/mobile/src/main/res/mipmap-hdpi/ic_launcher.png index e8f0bba..e2a4116 100644 Binary files a/mobile/src/main/res/mipmap-hdpi/ic_launcher.png and b/mobile/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/mobile/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/mobile/src/main/res/mipmap-hdpi/ic_launcher_foreground.png index 51192cb..13ff1ca 100644 Binary files a/mobile/src/main/res/mipmap-hdpi/ic_launcher_foreground.png and b/mobile/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/mobile/src/main/res/mipmap-hdpi/ic_launcher_round.png b/mobile/src/main/res/mipmap-hdpi/ic_launcher_round.png index 29eb69f..023ff8c 100644 Binary files a/mobile/src/main/res/mipmap-hdpi/ic_launcher_round.png and b/mobile/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/mobile/src/main/res/mipmap-mdpi/ic_launcher.png b/mobile/src/main/res/mipmap-mdpi/ic_launcher.png index 6da2a20..a5c72d4 100644 Binary files a/mobile/src/main/res/mipmap-mdpi/ic_launcher.png and b/mobile/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/mobile/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/mobile/src/main/res/mipmap-mdpi/ic_launcher_foreground.png index 8bb0f49..7ba09da 100644 Binary files a/mobile/src/main/res/mipmap-mdpi/ic_launcher_foreground.png and b/mobile/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/mobile/src/main/res/mipmap-mdpi/ic_launcher_round.png b/mobile/src/main/res/mipmap-mdpi/ic_launcher_round.png index 7476b1b..4586a47 100644 Binary files a/mobile/src/main/res/mipmap-mdpi/ic_launcher_round.png and b/mobile/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/mobile/src/main/res/mipmap-xhdpi/ic_launcher.png b/mobile/src/main/res/mipmap-xhdpi/ic_launcher.png index 09cae53..4c3fc60 100644 Binary files a/mobile/src/main/res/mipmap-xhdpi/ic_launcher.png and b/mobile/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/mobile/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/mobile/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png index f3701c4..358fed0 100644 Binary files a/mobile/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png and b/mobile/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/mobile/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/mobile/src/main/res/mipmap-xhdpi/ic_launcher_round.png index ea4e9df..f2c1714 100644 Binary files a/mobile/src/main/res/mipmap-xhdpi/ic_launcher_round.png and b/mobile/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/mobile/src/main/res/mipmap-xxhdpi/ic_launcher.png b/mobile/src/main/res/mipmap-xxhdpi/ic_launcher.png index b9e3136..cd9ddf9 100644 Binary files a/mobile/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/mobile/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/mobile/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/mobile/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png index 034af08..681531a 100644 Binary files a/mobile/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png and b/mobile/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/mobile/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/mobile/src/main/res/mipmap-xxhdpi/ic_launcher_round.png index 81a7b24..93bc094 100644 Binary files a/mobile/src/main/res/mipmap-xxhdpi/ic_launcher_round.png and b/mobile/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher.png index 4fb93d2..67c500b 100644 Binary files a/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png index dcc4a31..c65c677 100644 Binary files a/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png and b/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png index f164ee6..36e6c26 100644 Binary files a/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png and b/mobile/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/mobile/src/main/res/values/ic_launcher_background.xml b/mobile/src/main/res/values/ic_launcher_background.xml index 2acaec5..5fef994 100644 --- a/mobile/src/main/res/values/ic_launcher_background.xml +++ b/mobile/src/main/res/values/ic_launcher_background.xml @@ -1,4 +1,4 @@ - #3DAADC + #4272F5 \ No newline at end of file diff --git a/mobile/src/main/res/values/wear.xml b/mobile/src/main/res/values/wear.xml new file mode 100644 index 0000000..cfde799 --- /dev/null +++ b/mobile/src/main/res/values/wear.xml @@ -0,0 +1,6 @@ + + + dnd_sync + + \ No newline at end of file diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index e837386..cf3dc5e 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -24,7 +24,7 @@ --> + android:value="false" /> + android:exported="true" + android:enabled="true"> - - + @@ -70,6 +71,7 @@ + \ No newline at end of file diff --git a/wear/src/main/ic_launcher-playstore.png b/wear/src/main/ic_launcher-playstore.png index 31fcc5b..05ab18e 100644 Binary files a/wear/src/main/ic_launcher-playstore.png and b/wear/src/main/ic_launcher-playstore.png differ diff --git a/mobile/src/main/java/de/rhaeus/dndsync/DNDChangedReceiver.java b/wear/src/main/java/de/rhaeus/dndsync/DNDNotificationService.java similarity index 55% rename from mobile/src/main/java/de/rhaeus/dndsync/DNDChangedReceiver.java rename to wear/src/main/java/de/rhaeus/dndsync/DNDNotificationService.java index 04ed1cf..c2d50c3 100644 --- a/mobile/src/main/java/de/rhaeus/dndsync/DNDChangedReceiver.java +++ b/wear/src/main/java/de/rhaeus/dndsync/DNDNotificationService.java @@ -1,9 +1,9 @@ package de.rhaeus.dndsync; -import android.app.NotificationManager; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; + +import android.content.ComponentName; +import android.content.pm.PackageManager; +import android.service.notification.NotificationListenerService; import android.util.Log; import android.widget.Toast; @@ -18,50 +18,65 @@ import com.google.android.gms.wearable.Node; import com.google.android.gms.wearable.Wearable; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; - -public class DNDChangedReceiver extends BroadcastReceiver{ - private static final String TAG = "DNDChangedReceiver"; +public class DNDNotificationService extends NotificationListenerService { + private static final String TAG = "DNDNotificationService"; private static final String DND_SYNC_CAPABILITY_NAME = "dnd_sync"; private static final String DND_SYNC_MESSAGE_PATH = "/wear-dnd-sync"; + @Override + public void onListenerConnected() { + Log.d(TAG, "listener connected"); +// // We don't want to run a background service so disable and stop it +// // to avoid running this service in the background +// disableServiceComponent(); +// Log.i(TAG, "Disabling service"); +// +// try { +// stopSelf(); +// } catch(SecurityException e) { +// Log.e(TAG, "Failed to stop service"); +// } + } + private void disableServiceComponent() { + PackageManager p = getPackageManager(); + ComponentName componentName = new ComponentName(this, DNDNotificationService.class); + p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); + } + + @Override - public void onReceive(Context context, Intent intent) { - if (intent.getAction().equals(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED)) { - NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - int dndState = mNotificationManager.getCurrentInterruptionFilter(); - Log.d(TAG, "Current DND state is: " + dndState); - - new Thread(new Runnable() { - public void run() { - sendSyncRequest(context, dndState); - } - }).start(); - } + public void onInterruptionFilterChanged (int interruptionFilter) { + Log.d(TAG, "interruption filter changed to " + interruptionFilter); + // Unable to retrieve node with transcription capability +// Toast.makeText(getApplicationContext(), "interruption filter changed to " + interruptionFilter, Toast.LENGTH_LONG).show(); + + new Thread(new Runnable() { + public void run() { + sendDNDSync(interruptionFilter); + } + }).start(); } - private void sendSyncRequest(Context context, int dndState) { + private void sendDNDSync(int dndState) { // https://developer.android.com/training/wearables/data/messages // search nodes for sync CapabilityInfo capabilityInfo = null; try { capabilityInfo = Tasks.await( - Wearable.getCapabilityClient(context).getCapability( + Wearable.getCapabilityClient(this).getCapability( DND_SYNC_CAPABILITY_NAME, CapabilityClient.FILTER_REACHABLE)); } catch (ExecutionException e) { e.printStackTrace(); - Log.e(TAG, "oh god1", e); + Log.e(TAG, "execution error while searching nodes", e); return; } catch (InterruptedException e) { e.printStackTrace(); - Log.e(TAG, "oh god2", e); + Log.e(TAG, "interruption error while searching nodes", e); return; } @@ -75,18 +90,18 @@ private void sendSyncRequest(Context context, int dndState) { for (Node node : connectedNodes) { if (node.isNearby()) { byte[] data = new byte[2]; - data[0] = 1; // bedtime mode + data[0] = 0; // dnd mode data[1] = (byte) dndState; Task sendTask = - Wearable.getMessageClient(context).sendMessage(node.getId(), DND_SYNC_MESSAGE_PATH, data); - // You can add success and/or failure listeners, - // Or you can call Tasks.await() and catch ExecutionException + Wearable.getMessageClient(this).sendMessage(node.getId(), DND_SYNC_MESSAGE_PATH, data); + sendTask.addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Integer integer) { Log.d(TAG, "send successful!"); } }); + sendTask.addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { @@ -97,5 +112,4 @@ public void onFailure(@NonNull Exception e) { } } } - } diff --git a/wear/src/main/java/de/rhaeus/dndsync/DNDSyncListenerService.java b/wear/src/main/java/de/rhaeus/dndsync/DNDSyncListenerService.java index a46ee08..3db8ed0 100644 --- a/wear/src/main/java/de/rhaeus/dndsync/DNDSyncListenerService.java +++ b/wear/src/main/java/de/rhaeus/dndsync/DNDSyncListenerService.java @@ -59,41 +59,33 @@ public void onMessageReceived (MessageEvent messageEvent) { switch (mode) { case 0: //dnd { - mNotificationManager.setInterruptionFilter(dndStatePhone); + if (dndStatePhone != currentDndState) { + mNotificationManager.setInterruptionFilter(dndStatePhone); // Toast.makeText(getApplicationContext(), "DND set to " + dndStatePhone, Toast.LENGTH_LONG).show(); - Log.d(TAG, "DND set to " + dndStatePhone); + Log.d(TAG, "DND set to " + dndStatePhone); + } break; } case 1: //bedtime { - Log.d(TAG, "toggle bedtime mode"); - if(currentDndState == NotificationManager.INTERRUPTION_FILTER_ALL && dndStatePhone != NotificationManager.INTERRUPTION_FILTER_ALL) { - // watch dnd is off but phone dnd is not off -> turn bedtime mode on - Log.d(TAG, "toggle bedtime mode case 1"); - // create a handler to post messages to the main thread - Handler mHandler = new Handler(getMainLooper()); - mHandler.post(new Runnable() { - @Override - public void run() { - Toast.makeText(getApplicationContext(), "DNDSync enables bedtime mode", Toast.LENGTH_SHORT).show(); - } - }); - - toggleBedtimeMode(); - } else if (currentDndState != NotificationManager.INTERRUPTION_FILTER_ALL && dndStatePhone == NotificationManager.INTERRUPTION_FILTER_ALL) { - // watch dnd is not off but phone dnd is off -> turn bedtime mode off - Log.d(TAG, "toggle bedtime mode case 2"); - - // create a handler to post messages to the main thread - Handler mHandler = new Handler(getMainLooper()); - mHandler.post(new Runnable() { - @Override - public void run() { - Toast.makeText(getApplicationContext(), "DNDSync disables bedtime mode", Toast.LENGTH_SHORT).show(); - } - }); + if (dndStatePhone != currentDndState) { toggleBedtimeMode(); + // set DND just in case bedtime toggle does not work to have at least DND + mNotificationManager.setInterruptionFilter(dndStatePhone); + Log.d(TAG, "DND set to " + dndStatePhone); } + +// // now toggle bedtime mode +// Log.d(TAG, "toggle bedtime mode"); +// if(currentDndState == NotificationManager.INTERRUPTION_FILTER_ALL && dndStatePhone != NotificationManager.INTERRUPTION_FILTER_ALL) { +// // watch dnd is off but phone dnd is not off -> turn bedtime mode on +// Log.d(TAG, "DNDSync enables bedtime mode"); +// toggleBedtimeMode(); +// } else if (currentDndState != NotificationManager.INTERRUPTION_FILTER_ALL && dndStatePhone == NotificationManager.INTERRUPTION_FILTER_ALL) { +// // watch dnd is not off but phone dnd is off -> turn bedtime mode off +// Log.d(TAG, "DNDSync disables bedtime mode"); +// toggleBedtimeMode(); +// } break; } default: @@ -106,21 +98,36 @@ public void run() { } } - - private void toggleBedtimeMode() { - DNDSyncAccessService serv = DNDSyncAccessService.getSharedInstance(); - if (serv == null) { - Log.d(TAG, "accessibility not connected"); - return; - } - // turn on screen PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE); // PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "dndsync:MyWakeLock"); PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP , "dndsync:MyWakeLock"); wakeLock.acquire(2*60*1000L /*2 minutes*/); + DNDSyncAccessService serv = DNDSyncAccessService.getSharedInstance(); + if (serv == null) { + Log.d(TAG, "accessibility not connected"); + // create a handler to post messages to the main thread + Handler mHandler = new Handler(getMainLooper()); + mHandler.post(new Runnable() { + @Override + public void run() { + Toast.makeText(getApplicationContext(), "DNDSync can't toggle bedtime mode since Accessibility Service is not connected!", Toast.LENGTH_LONG).show(); + } + }); + return; + } else { + // create a handler to post messages to the main thread + Handler mHandler = new Handler(getMainLooper()); + mHandler.post(new Runnable() { + @Override + public void run() { + Toast.makeText(getApplicationContext(), "DNDSync toggles Bedtime Mode.", Toast.LENGTH_SHORT).show(); + } + }); + } + // wait a bit before touch input to make sure screen is on try { Thread.sleep(1000); @@ -157,7 +164,6 @@ private void toggleBedtimeMode() { private void vibrate() { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)); - } } diff --git a/wear/src/main/java/de/rhaeus/dndsync/DummyNotificationListener.java b/wear/src/main/java/de/rhaeus/dndsync/DummyNotificationListener.java deleted file mode 100644 index 04a4bcf..0000000 --- a/wear/src/main/java/de/rhaeus/dndsync/DummyNotificationListener.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.rhaeus.dndsync; - -import android.content.ComponentName; -import android.content.pm.PackageManager; -import android.service.notification.NotificationListenerService; -import android.service.notification.StatusBarNotification; -import android.util.Log; - -// https://stackoverflow.com/questions/27185609/android-wear-listen-to-incoming-notifications/38794028#38794028 -// https://github.com/blunden/DoNotDisturbSync/blob/master/wear/src/main/java/se/blunden/donotdisturbsync/DummyNotificationListener.java - -/** - * A dummy {@link NotificationListenerService} service that disables and stops itself. - * - * Its purpose is to allow users to add the app as a notification listener which - * automatically grants and enables android.permission.ACCESS_NOTIFICATION_POLICY - * that can't be enabled the normal way on the watch. - */ -public class DummyNotificationListener extends NotificationListenerService { - private static final String TAG = "DndDummyService"; - - @Override - public void onListenerConnected() { - // We don't want to run a background service so disable and stop it - // to avoid running this service in the background - disableServiceComponent(); - Log.i(TAG, "Disabling service"); - - try { - stopSelf(); - } catch(SecurityException e) { - Log.e(TAG, "Failed to stop service"); - } - } - - @Override - public void onNotificationPosted(StatusBarNotification sbn) { - // Override this method to be explicit that we don't eavesdrop on notifications - } - - private void disableServiceComponent() { - PackageManager p = getPackageManager(); - ComponentName componentName = new ComponentName(this, DummyNotificationListener.class); - p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); - } -} \ No newline at end of file diff --git a/wear/src/main/java/de/rhaeus/dndsync/MainActivity.java b/wear/src/main/java/de/rhaeus/dndsync/MainActivity.java index 38961d7..8110477 100644 --- a/wear/src/main/java/de/rhaeus/dndsync/MainActivity.java +++ b/wear/src/main/java/de/rhaeus/dndsync/MainActivity.java @@ -3,6 +3,7 @@ import android.app.Activity; import android.app.NotificationManager; import android.content.Context; +import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; @@ -23,11 +24,19 @@ protected void onCreate(Bundle savedInstanceState) { binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); +// Intent intent = new Intent(this, DummyNotificationListener.class); // fails because of permission +// startService(intent); + Button btnDndCheck = (Button) findViewById(R.id.btnDndCheck); btnDndCheck.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { - // Check if the notification policy access has been granted for the app. + +// Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS); //fails +// startActivity(intent); + + +// // Check if the notification policy access has been granted for the app. NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // int fil = mNotificationManager.getCurrentInterruptionFilter(); // Toast.makeText(getApplicationContext(), "DND permission filter: " + fil, Toast.LENGTH_SHORT).show(); @@ -53,6 +62,23 @@ public void onClick(View v) { } }); + Button btnEnableDND = (Button) findViewById(R.id.btnEnableDND); + btnEnableDND.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY); + } + }); + Button btnDisableDND = (Button) findViewById(R.id.btnDisableDND); + btnDisableDND.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL); + } + }); + + + // // Button button = (Button) findViewById(R.id.button); diff --git a/wear/src/main/res/layout/activity_main.xml b/wear/src/main/res/layout/activity_main.xml index 37ea2f4..940f4b3 100644 --- a/wear/src/main/res/layout/activity_main.xml +++ b/wear/src/main/res/layout/activity_main.xml @@ -8,28 +8,44 @@ tools:context=".MainActivity" tools:deviceIds="wear"> - - -