现在的Android是否还能实现程序自启动?【求助】
各位大神,想请教一下
1.现在的Android到底还能不能实现程序自启动?
2.开机自启动?
3.被强行KILL掉后,能否自启动?
我的毕业设计是一个计步器,如果不能自启动是不是就赤裸裸的鸡肋了呢?
自用设备三星S5,系统版本6.01
另外1.前台服务是不是改代码报错为什么呢?
Notification notification = new Notification(R.drawable.icon, getText(R.string.ticker_text), System.currentTimeMillis());Intent notificationIntent = new Intent(this, ExampleActivity.class);PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);notification.setLatestEventInfo(this, getText(R.string.notification_title), getText(R.string.notification_message), pendingIntent);startForeground(ONGOING_NOTIFICATION, notification);
2.我换了一种实现方式,程序还是被kill掉了
代码如下:
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);
}