Android小米红米启动新进程失败

Android Xiaomi Redmi failed to start new process

我有同步服务 运行 在一个单独的进程中

    <service
        android:name=".local_data.SyncService"
        android:exported="true"
        android:process=":sync">
        <intent-filter>
            <action android:name="android.content.SyncAdapter" />
        </intent-filter>

        <meta-data
            android:name="android.content.SyncAdapter"
            android:resource="@xml/syncadapter" />
    </service>

除小米外,每个 phone 它都成功启动新进程,在进程选择器中我只看到主进程。我尝试在主进程中启动我的同步服务,它工作正常。

这在小米上并不新鲜,因为小米有一个名为应用权限的功能,用户必须允许应用自动启动(服务)。

像这样让您的应用程序自动启动:

Settings > permissions > Autostart

您可以通过重定向到小米设备中的自动启动页面来请求自动启动权限,如下所示:

void showAutoStartPermission(){
    String manufacturer = "xiaomi";
    if (manufacturer.equalsIgnoreCase(android.os.Build.MANUFACTURER)) { 
        //this will open auto start screen where user can enable permission for your app
        Intent intent1 = new Intent();
        intent1.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
        startActivity(intent1);
    }
}