我基本上只是试验Android开发,几天前我遇到了这个名为“Go SMS Pro”的应用程序,其中可以设置不同颜色的通知(蓝色,绿色,橙色,粉红色和浅蓝色)。所以,我试图在我自己的应用程序中自己做这件事,但是我无法改变LED的颜色和闪烁的内部。我目前使用此代码:更改LED颜色的通知
public class MainActivity extends Activity {
static final int NOTIFICATION_ID = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(buttonOnClick);
}
public OnClickListener buttonOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Notification notification = new Notification(R.drawable.icon, "Hello", System.currentTimeMillis());
notification.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL;
notification.ledARGB = Color.BLUE;
notification.ledOnMS = 1000;
notification.ledOffMS = 300;
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(MainActivity.this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(MainActivity.this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
};
}
但正如我所说,它不工作,我想要的方式;相反,它只是默认延迟闪烁,而不是我在代码中设置的那个。
任何人都可以看到我的代码有什么问题,或者知道我是否必须做其他事情来实现这个目标?
我已经尝试将'notification.defaults'设置为'0'和'notification.ledARGB'设置为十六进制值(尽管'Color.BLUE'具有常量值'0xff0000ff'),但都没有事情工作。我也知道硬件可以做近似,但我确信它至少应该能够做到绿色,蓝色,橙色和粉红色。 – Frxstrem 2011-05-29 18:08:29
很奇怪。 ** Go SMS Pro **应用程序是否成功更改手机上的颜色?我知道一些手机有LED通知颜色变化的问题。 – Femi 2011-05-29 18:12:16
是的,它的确如此,至少对应于该应用程序中预设的颜色(如我所提到的,绿色,蓝色,橙色和粉红色)。但是,我尝试了一些其他应用程序,这些应用程序应该会改变LED的颜色,但不起作用,并且最终会显示绿色闪烁的光,而不管它们设置了什么颜色,就像我的应用程序一样。 – Frxstrem 2011-05-29 18:14:31