更改android中的短信的LED颜色

时间:2016-08-08 06:43:24

标签: android colors led

如何更改短信通知的LED颜色。我可以改变LED的颜色,但问题是当收到短信时它会显示默认的LED颜色。除非我清除短信通知。然后它显示我的LED颜色。

代码在这里:

package com.example.led;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.telephony.gsm.SmsMessage;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver
{

@Override
public void onReceive(Context context, Intent intent)
{
    //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();
    SmsMessage[] msgs = null;
    String str = "";
    String phoneNumber = "";
    if (bundle != null)
    {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
            phoneNumber = msgs[i].getOriginatingAddress();
        }
        //---display the new SMS message---
        if(phoneNumber.equals("+1234567890")) {
            NotificationManagerCompat nm = NotificationManagerCompat.from(context);
            NotificationCompat.Builder notif = new NotificationCompat.Builder(context);
            notif.setLights(0x990000, 100, 100);
            notif.setSmallIcon(R.mipmap.ic_launcher);
            notif.setContentTitle("Notification Title");
            nm.notify(5, notif.build());
            Toast.makeText(context, "Sender: " + phoneNumber, Toast.LENGTH_SHORT).show();
        } 
    }
}
}

0 个答案:

没有答案