40

android让软件自启动,求助

<application
    android:allowBackup="true"

    android:label="@string/app_name"
    android:supportsRtl="true" >
    <activity android:name="com.zmf.feiying.unityandroidlibrary.MainActivity" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <meta-data
            android:name="unityplayer.UnityActivity"
            android:value="true" />
    </activity>

    <receiver
        android:name="com.zmf.feiying.unityandroidlibrary.StartBootComplete"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter android:priority="1000" >
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.HOME" />
        </intent-filter>
    </receiver>
</application>





private final String ACTION_BOOT = "android.intent.action.BOOT_COMPLETED";

@Override
public void onReceive (Context context, Intent intent) {

    if (ACTION_BOOT.equals(intent.getAction())) {
        Intent intentMainActivity = new Intent(context, MainActivity.class);
        intentMainActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intentMainActivity);
    }
}

}
代码都写好了,就是放在手机上不好用,我手机是华为 android9.0的

查看全部
qq_32254597
飞了啊
2019/04/01 15:14
  • android-studio
  • 点赞
  • 收藏
  • 回答
    私信

3个回复