mirror of
https://github.com/AceDroidX/frp-Android.git
synced 2024-11-15 19:22:32 +08:00
增加开机自启动 (#8)
This commit is contained in:
parent
db9d92c976
commit
8498c391b9
|
@ -5,6 +5,8 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -35,6 +37,18 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver
|
||||
android:name=".AutoStartBroadReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter android:priority="1000">
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
|
||||
<category android:name="android.intent.category.HOME" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,23 @@
|
|||
package io.github.acedroidx.frp
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
class AutoStartBroadReceiver : BroadcastReceiver() {
|
||||
private val ACTION = "android.intent.action.BOOT_COMPLETED"
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
//开机启动
|
||||
val editor = context.getSharedPreferences("data", AppCompatActivity.MODE_PRIVATE)
|
||||
val auto_start = editor.getBoolean("auto_start", false)
|
||||
if (ACTION == intent.action && auto_start) {
|
||||
//开机启动
|
||||
val mainIntent = Intent(context, MainActivity::class.java)
|
||||
mainIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
context.startActivity(mainIntent)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package io.github.acedroidx.frp
|
||||
|
||||
import android.app.*
|
||||
import android.app.ActivityManager
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
@ -23,6 +25,7 @@ class MainActivity : AppCompatActivity() {
|
|||
val configname = "config.ini"
|
||||
|
||||
private lateinit var state_switch: SwitchCompat
|
||||
private lateinit var auto_start_switch: SwitchCompat
|
||||
|
||||
private lateinit var mService: ShellService
|
||||
private var mBound: Boolean = false
|
||||
|
@ -60,6 +63,15 @@ class MainActivity : AppCompatActivity() {
|
|||
state_switch = findViewById<SwitchCompat>(R.id.state_switch)
|
||||
state_switch.isChecked = mBound
|
||||
state_switch.setOnCheckedChangeListener { buttonView, isChecked -> if (isChecked) (startShell()) else (stopShell()) }
|
||||
val editor = getSharedPreferences("data", AppCompatActivity.MODE_PRIVATE)
|
||||
auto_start_switch = findViewById<SwitchCompat>(R.id.auto_start_switch)
|
||||
auto_start_switch.isChecked = editor.getBoolean("auto_start", false)
|
||||
if (auto_start_switch.isChecked) (startShell())
|
||||
auto_start_switch.setOnCheckedChangeListener { buttonView, isChecked ->
|
||||
val editor = editor.edit()
|
||||
editor.putBoolean("auto_start", isChecked)
|
||||
editor.apply();
|
||||
}
|
||||
if (mBound) {
|
||||
val intent = Intent(this, ShellService::class.java)
|
||||
bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||
|
@ -151,8 +163,7 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun isServiceRunning(serviceClass: Class<*>): Boolean {
|
||||
val manager =
|
||||
getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
val manager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
for (service in manager.getRunningServices(Int.MAX_VALUE)) {
|
||||
if (serviceClass.name == service.service.className) {
|
||||
return true
|
||||
|
|
|
@ -30,6 +30,12 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="切换开关" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/auto_start_switch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="开机自启动" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -46,6 +52,7 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="关于" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Space
|
||||
|
|
BIN
image/image3.png
Normal file
BIN
image/image3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
BIN
image/image4.png
Normal file
BIN
image/image4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
Loading…
Reference in New Issue
Block a user