当我从通知中调用活动时,我试图让我的屏幕变暗。这是我正在使用的代码:
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 0.01f;
getWindow().setAttributes(lp);
也许我在这里做错了什么,如果是这样,有人可以告诉我发生了什么以及为什么它没有按预期的方式工作?!
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);
}
}
这是请求的代码