How to automatically enable autostart of my applications in the Xiaomi Mi4i security menu?

My applications, if they are already installed, cannot start the service. If the service start must be configured in the security menu, then allow the use of these applications manually. And I want the setup not to be manual, but programmatically in my code service.

My code

  • Service

    The public class MyService extends the service {

    @Override
    public void onCreate() {
        super.onCreate();
    }
    
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Toast.makeText(this, "Service Started...", Toast.LENGTH_LONG).show();
        return Service.START_STICKY;
    }
    
    @Override
    public void onDestroy() {
        Toast.makeText(this, "Service Destroyed...", Toast.LENGTH_LONG).show();
    }
    
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    

    }

  • Android Manifest

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    
        <service
            android:name=".MyService"
            android:exported="false"
            android:enabled="true">
        </service>
    </application>
    

Please help me all ..: '(

+4
source share

Source: https://habr.com/ru/post/1620543/


All Articles