android开机自启前台显示,【03-10求助】现在的Android是否还能实现程序自启动?...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

回复 初音是谁 :public class MyService extends Service

public void onCreate() {

super.onCreate();

Log.d("Myservice", "onCreate");

manager=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

//通过 Builder 来创建 Notification 的

Notification.Builder builder=new Notification.Builder(this);

//设置 通知 图标

builder.setSmallIcon(R.mipmap.ic_launcher);

//设置 通知 显示标题

builder.setTicker("Hi");

//设置 通知栏 标题

builder.setContentTitle("步行运功");

//设置 通知内容

builder.setContentText("正在计步...");

//设置 提醒 声音/震动/指示灯

// builder.setDefaults(Notification.DEFAULT_ALL);

//设置 点击后的跳转 通过 pendingIntent 实现

Intent intent=new Intent(this,MenuActivity.class);

PendingIntent pendingIntent=PendingIntent.getActivity(this,0, intent,0);

builder.setContentIntent(pendingIntent);

//创建 通知

//安卓4.1 及其 以上使用 build()方法 ,以下的使用 builder.getNotification();

Notification notification=builder.build();

notification.flags |= Notification.FLAG_ONGOING_EVENT;

notification.flags |= Notification.FLAG_NO_CLEAR;

notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;

startForeground(1, notification);

}

我代码有没有问题。但是我的通知大概显示到15-30分钟,然后就消失了?是系统内存不足杀的吗?之前能保存几个小时。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值