Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to code a service that started when device booted.

java.lang.RuntimeException: Unable to start receiver packagename.BootReciever: android.content.ActivityNotFoundException: Unable to find explicit activity class {packagename/packagename.MainActivity$Companion}; have you declared this activity in your AndroidManifest.xml?

In my manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="packagename">

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.INJECT_EVENTS" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Translucent"
        android:fullBackupContent="@xml/backup_descriptor">
        <activity android:name="packagename.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name="packagename.RemoteService">
            <intent-filter>
                <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
            </intent-filter>
        </service>

        <receiver android:name="packagename.BootReciever"
            android:enabled="true"
            android:exported="true">
            <intent-filter android:directBootAware="true">
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="android.intent.action.REBOOT"/>
            </intent-filter>

        </receiver>

    </application>

</manifest>

When i open app, it will work well, however i want to launch application when boot completed. I push it into system/app and it crushes.

    override fun onReceive(p0: Context?, p1: Intent?) {
        if(p1?.action.equals("android.intent.action.BOOT_COMPLETED")){
            Log.e("Ahmet ","START PLSSSSSSSSSSSSS")
            val startIntent = Intent(p0,MainActivity.javaClass)
            startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            p0?.startActivity(startIntent)
        }
    }
}

MainActivity

class MainActivity : Activity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        appContext = applicationContext
        ServiceModul.startServices(this)
        finish()
    }

    companion object {
        lateinit var appContext: Context
    }


}

I signed the application, it has permissions, however on boot, it could not find MainActivity. I check package names like 3-4 times. What should i do?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
440 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...