改变LED颜色的通知 [英] Changing LED color for notifications

查看:179
本文介绍了改变LED颜色的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上只是尝试用Android开发,并且前两天我碰到这个应用程序称为的 GO短信,其中,除其他事项外,可设置不同的颜色(蓝色,绿色,橙色,粉红色和淡蓝色)的通知。所以,我试图做到这一点我自己在我自己的应用程序,但我不能改变neiher的颜色,也没有闪烁的内部的LED。我目前使用这个code:

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);
    }
  };
}

但正如我所说,这是行不通的,我希望它的方式;相反,它只是闪烁的普通绿茶的默认延迟,而不是一个我在code设置。

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.

有人能看到什么是错我的code,或者知道有没有做别的事情来实现这一目标?

Can anyone see what is wrong with my code, or know if I have to do something else to achieve this?

推荐答案

您可以使用此code:

You can use this code:

 private void RedFlashLight()
    {
    NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
    Notification notif = new Notification();
    notif.ledARGB = 0xFFff0000;
    notif.flags = Notification.FLAG_SHOW_LIGHTS;
    notif.ledOnMS = 100; 
    notif.ledOffMS = 100; 
    nm.notify(LED_NOTIFICATION_ID, notif);
    }

而不是使用ARGB值作为例子显示,你可以使用android.graphics.Color类中整型属性,使色彩以及

Instead of using ARGB value as the example show, you can use int property inside android.graphics.Color class to get the color as well

这篇关于改变LED颜色的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆