List of usage examples for android.content Intent ACTION_DREAMING_STARTED
String ACTION_DREAMING_STARTED
To view the source code for android.content Intent ACTION_DREAMING_STARTED.
Click Source Link
From source file:com.farmerbb.secondscreen.service.NotificationService.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override/*from ww w . j a v a 2 s . com*/ public void onCreate() { // Load preferences SharedPreferences prefCurrent = U.getPrefCurrent(this); SharedPreferences prefMain = U.getPrefMain(this); // Register broadcast receivers for screen on and user present final IntentFilter filter1 = new IntentFilter(); final IntentFilter filter2 = new IntentFilter(); filter1.addAction(Intent.ACTION_SCREEN_ON); filter1.addAction(Intent.ACTION_DREAMING_STARTED); filter2.addAction(Intent.ACTION_USER_PRESENT); registerReceiver(screenOnReceiver, filter1); registerReceiver(userPresentReceiver, filter2); DisplayManager manager = (DisplayManager) getSystemService(DISPLAY_SERVICE); manager.registerDisplayListener(listener, null); // Intent to launch MainActivity when notification is clicked Intent mainActivityIntent = new Intent(this, MainActivity.class); PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(this, 0, mainActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Build the notification mBuilder = new NotificationCompat.Builder(this).setContentIntent(mainActivityPendingIntent) .setSmallIcon(R.drawable.ic_action_dock) .setContentTitle(getResources().getString(R.string.notification)) .setContentText( prefCurrent.getString("profile_name", getResources().getString(R.string.action_new))) .setOngoing(true); // Set action buttons setActionButton(prefMain.getString("notification_action_2", "turn-off"), prefCurrent, 0); setActionButton(prefMain.getString("notification_action", "lock-device"), prefCurrent, 1); // Respect setting to hide notification if (prefMain.getBoolean("hide_notification", false)) mBuilder.setPriority(Notification.PRIORITY_MIN); // Set notification color on Lollipop if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setColor(getResources().getColor(R.color.primary_dark)) .setVisibility(Notification.VISIBILITY_PUBLIC); } // Start NotificationService startForeground(1, mBuilder.build()); // Draw system overlay, if needed if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Settings.canDrawOverlays(this) && prefCurrent.getString("rotation_lock_new", "fallback").equals("landscape")) { windowManager = (WindowManager) getSystemService(WINDOW_SERVICE); WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; view = new View(this); windowManager.addView(view, params); } }