各位大神,想請教一下
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);
}
uj5u.com熱心網友回復:
提高Service 的優先級,最好寫兩個Service ,Service A被殺死后啟動Service B,Service B被殺死后啟動Service A,
相互守護,保證兩個Service 有一個存在
uj5u.com熱心網友回復:
這種方法很沒有理由啊,APP被殺死的話所有Service都被殺死了,除非有一個Service 是系統級Service
uj5u.com熱心網友回復:
現在的主流rom都有自動啟動, 關聯啟用的權限管理. 并且還有自動清后臺功能.想自動啟動, 非常難了.
除非使用非常規方式, 類似的病毒的手段.
uj5u.com熱心網友回復:
----------------------------------------------------------------------
我就是看了論壇上的各種方法,監聽開機廣播,一點辦法都沒有。
是不是可以理解為,手機重啟后是沒有辦法監聽手機開機的廣播的?
uj5u.com熱心網友回復:
這個沒試過, 不過系統應該是可以限制你啟用程式的作, 或者直接不讓你回應這個廣播.uj5u.com熱心網友回復:
這個需要在手機上設定吧?uj5u.com熱心網友回復:
小白路過
uj5u.com熱心網友回復:
請求系統alert權限設定一個像素為1 的window
時刻保持在前臺
uj5u.com熱心網友回復:
這個貌似在低版本是非常有效uj5u.com熱心網友回復:
如今已經不管用嘍
uj5u.com熱心網友回復:
這個貌似在低版本是非常有效
請求系統alert權限
設定一個像素為1 的window
時刻保持在前臺
如今已經不管用嘍
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/37341.html
標籤:Android
上一篇:天氣預報
