增加开机启动
This commit is contained in:
@@ -4,6 +4,14 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
signingConfigs {
|
||||||
|
getByName("debug") {
|
||||||
|
storeFile = file("../app/swkey.jks")
|
||||||
|
storePassword = "123456"
|
||||||
|
keyPassword = "123456"
|
||||||
|
keyAlias = "android"
|
||||||
|
}
|
||||||
|
}
|
||||||
namespace = "com.shuwei.intelligent.shelves"
|
namespace = "com.shuwei.intelligent.shelves"
|
||||||
compileSdk = 34
|
compileSdk = 34
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
tools:ignore="ScopedStorage" />
|
tools:ignore="ScopedStorage" />
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".App"
|
android:name=".App"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -36,6 +38,15 @@
|
|||||||
android:name=".ShelfActivity"
|
android:name=".ShelfActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
|
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
|
||||||
|
|
||||||
|
<receiver
|
||||||
|
android:name=".utils.BootReceiver"
|
||||||
|
android:enabled="true"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.shuwei.intelligent.shelves
|
package com.shuwei.intelligent.shelves
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
|
import com.shuwei.intelligent.shelves.utils.BootReceiver
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: star
|
* @author: star
|
||||||
@@ -18,6 +21,8 @@ class App : Application() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
app = this
|
app = this
|
||||||
|
val filter = IntentFilter(Intent.ACTION_BOOT_COMPLETED)
|
||||||
|
registerReceiver(BootReceiver(), filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.shuwei.intelligent.shelves.utils
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import com.shuwei.intelligent.shelves.HomeActivity
|
||||||
|
import kotlin.jvm.java
|
||||||
|
|
||||||
|
class BootReceiver : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
if (Intent.ACTION_BOOT_COMPLETED == intent.action) {
|
||||||
|
// 启动服务或Activity
|
||||||
|
val launchIntent = Intent(context, HomeActivity::class.java)
|
||||||
|
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
context.startActivity(launchIntent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user