i'm writting a application,one function of which is shutting down the phone.so what should i write in the android studio now? i found the code segment in the net.but it did not build normally
what added in the MainActivity.kt
fun shutdown(){
val intent:Intent = Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN")
intent.putExtra("android.intent.extra.KEY_CONFIRM",true)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
what added in the AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dotzhang.toolbox"
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.SHUTDOWN"/></maniest>
error information
01/11 16:38:46: Launching 'app' on Nexus 5X API 30.
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
List of apks:
[0] 'D:\javaproj\toolbox\app\build\outputs\apk\debug\app-debug.apk'
Installation failed due to: 'INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: Package com.dotzhang.toolbox tried to change user null'
Retry
here is AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dotzhang.toolbox"
android:sharedUserId="android.uid.system">
<uses-permission android:name="android.permission.SHUTDOWN"/>
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Toolbox">
<activity android:name=".MainActivity"
android:exported="true"
android:label="toolbox">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>