Android Studio Notifications

3

How to turn on the screen of the mobile when a mobile application launches a notification?

My application launches this type of notifications depending on specific parameters, I want that apart from vibrating and sounding turn on the screen too, what a pity if I have not made myself understood.

public void carrera(int id, int iconid, String titulo, String contenido) {
    Intent intent = new Intent(this, MapsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contIntent = PendingIntent.getActivity(MapsActivity.this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                    .setSmallIcon(iconid)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                            R.mipmap.poder_amarillo))
                    .setContentTitle(titulo)
                    .setContentIntent(contIntent)
                    .setSound((Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.vip)))
                    //.setVibrate(new long[]{ 1000,500,1000,800,1000,1500 })
                    .setLights(Color.RED,3000,3000)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                    .setPriority(Notification.PRIORITY_MAX)
                    .setContentText(contenido);
    notificacion.notify(id, builder.build());
}
    
asked by David Peña 22.09.2016 в 22:29
source

1 answer

1

Try to turn on the screen with this code:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
wl.acquire(3000);
wl.release();

and add the following permission to the manifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />
    
answered by 13.10.2016 в 20:40