自定义通知?

时间:2018-04-28 20:41:44

标签: android push-notification notifications

我想询问即使手机被锁定,我也可以如何实施自定义通知。

例如,我有这项服务,可以帮助推送通知。

public class NotifyService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate(){
        Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        Intent intent1 = new Intent(this.getApplicationContext(), HomeMenuActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent1, 0);

        Notification mNotify = new Notification.Builder(this)
                .setContentTitle("Checker")
                .setContentText("Welcome here")
                .setSmallIcon(R.drawable.app_icon)
                .setContentIntent(pIntent)
                .setSound(sound)
                .addAction(0, "Loading...", pIntent)
                .build();

        mNM.notify(1, mNotify);
    }
}

但是,我想知道如何实现下面附图所示的内容。here

1 个答案:

答案 0 :(得分:0)

锁定屏幕上的通知出现是从棒棒糖版本开始的。因此,您需要设置优先级最高或最高通知,然后当设备被锁定时它将显示在锁定屏幕上,并且还将显示为抬头通知。< / p>