我基本上只是在尝试Android开发,几天前我遇到了一个名为“ Go SMS Pro ”的应用程序,它可以设置不同颜色的通知(蓝色、绿色、橙色、粉色和浅色)蓝色的)。因此,我尝试在自己的应用程序中自己执行此操作,但是我无法更改 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);
}
};
}
但正如我所说,它并没有按照我想要的方式工作。相反,它只是在默认延迟下以常规绿色闪烁,而不是我在代码中设置的延迟。
任何人都可以看到我的代码有什么问题,或者知道我是否需要做其他事情来实现这一点?