Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 10.0应用程序启动时启动_Android_Boot_Launch - Fatal编程技术网

Android 10.0应用程序启动时启动

Android 10.0应用程序启动时启动,android,boot,launch,Android,Boot,Launch,我们有一个android应用程序,我们打算在手机启动时启动。 通过Android 10中的一些代码尝试,我们意识到在Android 8.0之后启动应用程序是不可能的。在之前的安卓6中,这是可能的。 即使在物理设备/手机/仿真器Android 10中,我们也在AutoStart列表中授予了应用程序权限。 > 我们在Android 10中所做的尝试:下面是代码的3部分-AndroidManifest.xml、MyActivity.java、MyBroadcastReceiver.java publi

我们有一个android应用程序,我们打算在手机启动时启动。 通过Android 10中的一些代码尝试,我们意识到在Android 8.0之后启动应用程序是不可能的。在之前的安卓6中,这是可能的。 即使在物理设备/手机/仿真器Android 10中,我们也在AutoStart列表中授予了应用程序权限。 >

我们在Android 10中所做的尝试:下面是代码的3部分-AndroidManifest.xml、MyActivity.java、MyBroadcastReceiver.java

public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent i = new Intent(context, MainActivity.class);
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(i);
Log.d(TAG, "------ tried to launch MainActivity -------"); // this is printed
}
}
}
1) AndroidManifest.xml

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /><uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<activity android:name=".MainActivity"  android:launchMode="singleTop" android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name=".MyBroadcastReceiver" android:enabled="true" android:exported="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
3) MyBroadcastReceiver.java

public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent i = new Intent(context, MainActivity.class);
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(i);
Log.d(TAG, "------ tried to launch MainActivity -------"); // this is printed
}
}
}

在启动时启动应用程序可能会让用户感到恼火。你可以开始一个新的工作。根据您的设备,引导目的可以有多种不同的形式。我试着在这里抓住他们

在您的舱单中:

<receiver android:name=".receiver.BootReceiver" // YOUR RECEIVER HERE
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
            <action android:name="android.intent.action.REBOOT" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
            <action android:name="android.intent.action.ACTION_SHUTDOWN" />
        </intent-filter>
    </receiver>

在启动时启动应用程序可能会让用户感到恼火。你可以开始一个新的工作。根据您的设备,引导目的可以有多种不同的形式。我试着在这里抓住他们

在您的舱单中:

<receiver android:name=".receiver.BootReceiver" // YOUR RECEIVER HERE
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
        <intent-filter>
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
            <action android:name="android.intent.action.REBOOT" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
            <action android:name="android.intent.action.ACTION_SHUTDOWN" />
        </intent-filter>
    </receiver>

@谢谢你的建议。我编辑了代码:(a)在MyBrodcastReceiver.java::onReceive()中添加了manifext SYSTEM\u ALERT\u窗口(b)——我编辑了-->>Intent I=newintent(context,MainActivity.class);i、 设置动作(意图、动作和主);i、 addCategory(意图.类别\发射器);i、 addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);背景。起始触觉(i);Log.d(标记“----已尝试启动MainActivity------”;//这是打印在日志中…但应用程序未启动…您可以显示代码吗?编辑您的第一篇文章以包含更改以检查它们out@Dan:我在上面的帖子中编辑了代码。我在我的Redmi 6 pro MIUI Global 11.0.7.1、Android 9 PKQ1.180917.001中测试/部署该应用程序。我甚至在emulator Pixel 2 x86 Android 10.0+上进行了尝试/测试。同样的结果是,启动后,应用程序不会启动。在Redmi 6 pro中,应用程序甚至被登记在AutoStart权限列表中。您是否检查了覆盖权限?你确定你已经把它们放到你的应用程序了吗?@Dan:谢谢你的建议。我编辑了代码:(a)在MyBrodcastReceiver.java::onReceive()中添加了manifext SYSTEM\u ALERT\u窗口(b)——我编辑了-->>Intent I=newintent(context,MainActivity.class);i、 设置动作(意图、动作和主);i、 addCategory(意图.类别\发射器);i、 addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);背景。起始触觉(i);Log.d(标记“----已尝试启动MainActivity------”;//这是打印在日志中…但应用程序未启动…您可以显示代码吗?编辑您的第一篇文章以包含更改以检查它们out@Dan:我在上面的帖子中编辑了代码。我在我的Redmi 6 pro MIUI Global 11.0.7.1、Android 9 PKQ1.180917.001中测试/部署该应用程序。我甚至在emulator Pixel 2 x86 Android 10.0+上进行了尝试/测试。同样的结果是,启动后,应用程序不会启动。在Redmi 6 pro中,应用程序甚至被登记在AutoStart权限列表中。您是否检查了覆盖权限?您是否确保已将它们提供给您的应用程序?感谢您的响应。基本上,通过onReceive()中引导期间的服务启动,已完成并测试。引导完成后,我们在通知抽屉中有一个通知。当用户点击该通知时,我们将启动应用程序(这是通过PendingDent()完成的)。这是好的和工作。但我们的目标/要求是——在Android 8+中,另外,我们需要在引导期间启动应用程序,而不需要点击通知手动启动。感谢您的响应。基本上,通过onReceive()中引导期间的服务启动完成并测试。引导完成后,我们在通知抽屉中有一个通知。当用户点击该通知时,我们将启动应用程序(这是通过PendingDent()完成的)。这是好的和工作。但我们的目标/要求是——在Android 8+中,我们还需要在启动时启动应用程序,而不需要点击通知手动启动。