I am basically just experimenting with Android development, and a couple of days ago I came across this app called "Go SMS Pro", which, among other things, can set up notifications in different colors (blue, green, orange, pink and light blue). So, I have tried to do this myself in my own app, however I cannot change neiher the color nor the blinking internal of the LED. I currently use this code:
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);
}
};
}
But as I said, it doesn't work the way I want it to; instead it just blinks in regular green with the default delay, and not the one I have set in my code.
Can anyone see what is wrong with my code, or know if I have to do something else to achieve this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…