现在的Android是否还能实现程序自启动?【求助】

m0_37546577 2017-03-10 01:19:23
各位大神,想请教一下
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);
}

...全文
405 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fei得更高 2020-04-30
  • 打赏
  • 举报
回复
引用 10 楼 木羊1 的回复:
[quote=引用 9 楼 fei得更高 的回复:]
[quote=引用 8 楼 Sun_TTTT 的回复:]
请求系统alert权限
设置一个像素为1 的window
时刻保持在前台
这个貌似在低版本是非常有效[/quote]

如今已经不管用喽[/quote]是的,被禁止了
木羊muyang 2020-04-29
  • 打赏
  • 举报
回复
引用 9 楼 fei得更高 的回复:
[quote=引用 8 楼 Sun_TTTT 的回复:]
请求系统alert权限
设置一个像素为1 的window
时刻保持在前台
这个貌似在低版本是非常有效[/quote]

如今已经不管用喽
fei得更高 2019-03-25
  • 打赏
  • 举报
回复
引用 8 楼 Sun_TTTT 的回复:
请求系统alert权限
设置一个像素为1 的window
时刻保持在前台
这个貌似在低版本是非常有效
Sun_TTTT 2017-03-17
  • 打赏
  • 举报
回复
请求系统alert权限 设置一个像素为1 的window 时刻保持在前台
墨聞 2017-03-15
  • 打赏
  • 举报
回复
小白路过
头发还没秃a 2017-03-10
  • 打赏
  • 举报
回复
引用 1 楼 qq_34364155 的回复:
提高Service 的优先级, 最好写两个Service ,Service A被杀死后启动Service B,Service B被杀死后启动Service A, 相互守护,保证两个Service 有一个存在
这种方法很没有理由啊,APP被杀死的话所有Service都被杀死了,除非有一个Service 是系统级Service
寒冰大神 2017-03-10
  • 打赏
  • 举报
回复
提高Service 的优先级, 最好写两个Service ,Service A被杀死后启动Service B,Service B被杀死后启动Service A, 相互守护,保证两个Service 有一个存在
net_morning 2017-03-10
  • 打赏
  • 举报
回复
这个需要在手机上设置吧?
xiaohuh421 2017-03-10
  • 打赏
  • 举报
回复
这个没试过, 不过系统应该是可以限制你启用程序的作, 或者直接不让你响应这个广播.
m0_37546577 2017-03-10
  • 打赏
  • 举报
回复
引用 3 楼 xiaohuh421 的回复:
现在的主流rom都有自动启动, 关联启用的权限管理. 并且还有自动清后台功能. 想自动启动, 非常难了. 除非使用非常规方式, 类似的病毒的手段.
---------------------------------------------------------------------- 我就是看了论坛上的各种方法,监听开机广播,一点办法都没有。 是不是可以理解为,手机重启后是没有办法监听手机开机的广播的?
xiaohuh421 2017-03-10
  • 打赏
  • 举报
回复
现在的主流rom都有自动启动, 关联启用的权限管理. 并且还有自动清后台功能. 想自动启动, 非常难了. 除非使用非常规方式, 类似的病毒的手段.

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧