I’m trying to get my screen to go dim when I call an activity from a notification. Here is the code I am using:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 0.01f;
getWindow().setAttributes(lp);
Maybe I am doing something wrong here, if so can someone tell me whats going on and why its not working the way its supposed to?!
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
public class NoteMe extends Activity {
/** Called when the activity is first created. */
NotificationManager nm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String title = "Example text";
String contentText = "Full hello world!";
String text = "Starting Notification!";
nm = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
long when = System.currentTimeMillis();
int icon = R.drawable.ic_launcher;
Intent intent = new Intent(getBaseContext(), MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(
getBaseContext(), 0, intent, 0);
Notification notification = new Notification(icon, text, when);
notification.setLatestEventInfo(getBaseContext(), title, contentText,
contentIntent);
notification.flags = Notification.FLAG_ONGOING_EVENT;
int NOTIFICATION_ID = 10;
nm.notify(NOTIFICATION_ID, notification);
}
}
Here is the requested code
You code is 100% correct. There are two possibilities the first is the most likely
1) The activity is not getting called off the notification. I believe there is a special way that you fire off from a notification involving pending intents. I would guess thats the problem. Just to be sure put some breakpoints in onCreate and onStart to see if it ever gets called. Or just put a log statement near your code to see if it gets called. I’m guessing it never gets called.
2) The adjustment you are making 0.1f is not visible change.
Please review this and just make sure notifications are being received:
http://www.vogella.com/articles/AndroidNotifications/article.html
One difference I see is getContextBase() vs. this
If its not that it looks like maybe MainActivity.class manifest declaration might not be right.