banner
RustyNail

RustyNail

coder. 【blog】https://rustynail.me 【nostr】wss://ts.relays.world/ wss://relays.world/nostr

不被輕易殺死

我不想死啊#

image

寫了個 Android 端的網絡懸浮窗,但是經常被系統(Android Oreo)把後台殺掉,

就查了很多如: 如何讓 android app 像 *** 流氓安全管家一樣不被輕易殺死(

做了以下工作:

service 被殺的時候發一個廣播奶自己一口#

 @Override
    public void onDestroy() {
        stopForeground(true);
        Intent intent = new Intent(getString(R.string.BACK_SERVICE_NAME));
        sendBroadcast(intent);
        super.onDestroy();
    }

public class ProtectBroadcast extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(context.getString(R.string.BACK_SERVICE_NAME))) {
            Toast.makeText(context, "Traffic Service Restarting..", Toast.LENGTH_SHORT).show();
            Intent intentStart = new Intent();
            intentStart.setClass(context, BackService.class);
            context.startService(intent);
        }
    }
}

但好像沒啥用,因為連destroy 方法都沒來得及執行。。。

Service 的啟動命令#

改為Sticky

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_STICKY;
    }

開守護進程#

開兩個 service,互相喚醒

在 Android 8.0 上好像沒啥用。。

最後#

沒轍

下了個軟件把 app 轉為系統 app... 做個流氓軟件還挺難哈。。

image

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。