增强开机启动
This commit is contained in:
Generated
+1
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|||||||
@@ -27,19 +27,27 @@
|
|||||||
android:excludeFromRecents="false"
|
android:excludeFromRecents="false"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
android:screenOrientation="landscape"
|
android:screenOrientation="landscape"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize">
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
|
android:clearTaskOnLaunch="true"
|
||||||
|
android:stateNotNeeded="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||||
|
<category android:name="android.intent.category.HOME" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".BootReceiver"
|
android:name=".BootReceiver"
|
||||||
android:exported="true">
|
android:exported="true"
|
||||||
|
android:enabled="true"
|
||||||
|
android:directBootAware="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,29 @@ package cn.flyzxf.FengTv
|
|||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
|
||||||
class BootReceiver : BroadcastReceiver() {
|
class BootReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
|
if (intent.action == Intent.ACTION_BOOT_COMPLETED ||
|
||||||
|
intent.action == "android.intent.action.QUICKBOOT_POWERON" ||
|
||||||
|
intent.action == "com.htc.intent.action.QUICKBOOT_POWERON") {
|
||||||
|
|
||||||
|
// 延迟启动,等系统完全就绪
|
||||||
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
|
try {
|
||||||
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
val launchIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
||||||
launchIntent?.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
if (launchIntent != null) {
|
||||||
|
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||||
|
Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED or
|
||||||
|
0x01000000) // FLAG_ACTIVITY_LAUNCH_FROM_HISTORY (API 31+)
|
||||||
context.startActivity(launchIntent)
|
context.startActivity(launchIntent)
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}, 3000L) // 延迟 3 秒确保系统已就绪
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
#!/system/bin/sh
|
||||||
|
# ============================================================
|
||||||
|
# FengTV - 设置为默认启动器(HOME桌面)
|
||||||
|
# 需要在 root 权限下执行(adb root 或 su)
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
PACKAGE="cn.flyzxf.FengTv"
|
||||||
|
ACTIVITY="cn.flyzxf.FengTv.MainActivity"
|
||||||
|
|
||||||
|
echo "============================================"
|
||||||
|
echo " FengTV 开机自启设置脚本"
|
||||||
|
echo "============================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# 检查 root
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "❌ 需要 root 权限!请用 adb root 或以 su 执行"
|
||||||
|
echo " 用法: adb root && adb shell < 此脚本"
|
||||||
|
echo " 或: 在终端模拟器中 su -c 'sh 此脚本'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ 已获得 root 权限"
|
||||||
|
|
||||||
|
# 方法1: 设置默认 HOME 启动器(最可靠)
|
||||||
|
echo ""
|
||||||
|
echo "📌 正在设置 FengTV 为默认启动器..."
|
||||||
|
|
||||||
|
# 清除旧的默认启动器设置
|
||||||
|
pm clear-defaults 2>/dev/null
|
||||||
|
|
||||||
|
# 将 FengTV 设置为默认 HOME
|
||||||
|
cmd package set-home-activity "$PACKAGE/$ACTIVITY" 2>/dev/null
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "✅ 已设置 FengTV 为默认桌面"
|
||||||
|
else
|
||||||
|
echo "⚠️ set-home-activity 失败,尝试备用方法..."
|
||||||
|
|
||||||
|
# 备用方法:直接修改系统设置
|
||||||
|
settings put secure default_input_method "$PACKAGE/$ACTIVITY" 2>/dev/null
|
||||||
|
|
||||||
|
# 对于 Android TV,使用 HOME 设置
|
||||||
|
if [ -d /data/system/users/0 ]; then
|
||||||
|
# 直接写入 role 管理器
|
||||||
|
pm grant "$PACKAGE" android.permission.SET_ACTIVITY_WATCHER 2>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "⚠️ 请手动设置:设置 → 应用 → 默认应用 → 桌面 → 选择 FengTV"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 方法2: 添加开机自启动白名单(针对小米/华为等国产系统)
|
||||||
|
echo ""
|
||||||
|
echo "📌 尝试添加开机自启动白名单..."
|
||||||
|
|
||||||
|
# 常见厂商白名单
|
||||||
|
for PROVIDER in "miui" "huawei" "oppo" "vivo" "oneplus" "smartisan" "meizu"; do
|
||||||
|
case "$PROVIDER" in
|
||||||
|
"miui")
|
||||||
|
# 小米 MIUI
|
||||||
|
settings put global power_supply_start_delay 0 2>/dev/null
|
||||||
|
appops set "$PACKAGE" AUTO_START allow 2>/dev/null
|
||||||
|
;;
|
||||||
|
"huawei")
|
||||||
|
# 华为 EMUI
|
||||||
|
settings put secure hw_auto_start_app_list "$PACKAGE" 2>/dev/null
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# 方法3: 禁用系统的电池优化(防止杀后台)
|
||||||
|
echo ""
|
||||||
|
echo "📌 禁用电池优化..."
|
||||||
|
dumpsys deviceidle whitelist +"$PACKAGE" 2>/dev/null
|
||||||
|
pm grant "$PACKAGE" android.permission.DEVICE_POWER 2>/dev/null
|
||||||
|
appops set "$PACKAGE" RUN_ANY_IN_BACKGROUND allow 2>/dev/null
|
||||||
|
|
||||||
|
# 方法4: 对于 Android 8+,添加为持久化应用(需预置)
|
||||||
|
# 非系统应用可能不支持,但试试无害
|
||||||
|
echo ""
|
||||||
|
echo "📌 尝试注册为系统级自启应用..."
|
||||||
|
if [ -f /data/system/packages.xml ]; then
|
||||||
|
echo " 跳过(非系统分区操作)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "============================================"
|
||||||
|
echo " ✅ 设置完成!"
|
||||||
|
echo "============================================"
|
||||||
|
echo ""
|
||||||
|
echo "重启电视后 FengTV 将自动启动"
|
||||||
|
echo ""
|
||||||
|
echo "如果仍然无法自启,请尝试:"
|
||||||
|
echo " 1. 在电视设置中关闭 FengTV 的"省电优化""
|
||||||
|
echo " 2. 将 FengTV 加入"受保护应用"列表"
|
||||||
|
echo " 3. 检查设置 → 应用 → 默认应用 → 桌面 → 选择 FengTV"
|
||||||
|
echo ""
|
||||||
Reference in New Issue
Block a user