android led通知代码

标签 android notifications led

我正在尝试让我手机上的 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/

相关文章:

c++ - 我如何知道 C++ 中所有者对象的地址?

c - 数字显示不正确,无法控制特定引脚的输出

c - 使用本地时间 [ARDUINO] LED 无法打开

android - 用于真实设备的 IBM Worklight SQL 适配器

Android JDBC连接导致ctahttp异常

javascript - 在expo react-native中打开键盘时如何隐藏TabBar

android - 如何使用 Jetpack Compose 在 TextField 中应用掩码日期(mm/dd/yyyy)?

java - 使用警报管理器的 Android 通知不起作用

Flutter:预定的通知日期时间

python - 如何将单个电位计值转换为 R、G、B?