我在舱单上的许可
使用权限android:name=“android.permission.u服务”
服务是
android:stopwithtask=“错误”
onstartcommand返回start\u并创建此代码的通知
私有void startforegroundservice(){
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
notification = new Notification.Builder(this, "SEX")
.setContentTitle("getText(R.string.notification_title)")
.setContentText("getText(R.string.notification_message)")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentIntent(pendingIntent)
.setTicker("ssss")
.build();
}else {
notification = new Notification.Builder(this)
.setContentTitle("getText(R.string.notification_title)")
.setContentText("getText(R.string.notification_message)")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentIntent(pendingIntent)
.setTicker("ssss")
.build();
}
startForeground(423, notification);
}
但如果我按“全部清除”按钮,我的服务就没用了
1条答案
按热度按时间7lrncoxx1#
你需要的是一个持续的通知,把它放在你的电脑上
Notification.Builder
对象: