時,屏幕不會變暗當我從通知中調用某個活動時,我試圖讓屏幕變暗。這裏是代碼我使用:當我將它告訴
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);
}
}
這裏是請求的代碼
請張貼顯示解僱通知的代碼。 – 2012-07-19 18:54:40
@CodeDroid我把它給你。 – linuxrox 2012-07-19 19:07:01
好的。您還需要在調用亮度的MainActivity中放置日誌或調試斷點。查看它是否達到該代碼。您擁有的代碼將調整僅執行屏幕的亮度。 – 2012-07-20 00:57:51