如何自动启用小米Mi4i安全菜单中的自动启动我的应用程序?

时间:2015-12-17 11:57:22

标签: android service autostart

我的应用已安装,无法启动服务。如果必须在安全菜单中设置运行服务,然后允许此应用程序进行手动设置。我希望设置不是手动设置,而是在我的代码服务中以编程方式。

我的代码,

  • 服务

    公共类MyService扩展了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>
    

请帮助我任何人......:'(

0 个答案:

没有答案