我正在尝试让我手机上的 Led 通知以特定顺序和不同颜色闪烁。
package com.example.led1;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.Menu;
//import android.graphics.Color;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
Notification notf = new NotificationCompat.Builder(this)
.setAutoCancel(false)
.setLights(0xffff00, 1000, 100)
.setLights(0xff0000, 5000, 100)
.setLights(0x0000FF, 10000, 100)
.build();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(2, notf);
// new Timer().scheduleAtFixedRate(notf, 100,5000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
} `
当应用程序在我的手机上运行时,它只会闪烁三个 setLights
命令的最后一种颜色。我如何按顺序运行这三个 setLights
并可能添加一个 while 循环?
最佳答案
坦率地说:你不应该那样做。这就是它没有集成的原因。 这可能会让用户更加恼火,因为它实际上很有用。
LED 应该(如果有的话)仅以一种颜色闪烁。这是Android的一致性设计原则之一。请遵守它们。
如果您仍然想“淹没”用户体验,请告知可以通过使用无数引导通知来实现它。
关于android led通知代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21775728/