platform
RK3399 + Android 8.1
problem
The shutdown interface used in the old SDK is not available for testing on 8.1, the code is as follows:
//shutdown now
String action = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
Intent shutdown = new Intent(action);
shutdown.putExtra("android.intent.extra.KEY_CONFIRM", false);
shutdown.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(shutdown);
finish();
}catch(Exception e){
e.printStackTrace();
}
It was found that no activity was found during execution.
the reason
|-- frameworks/base/core/java/android/content/Intent.java
旧SDK:
public static final String ACTION_REQUEST_SHUTDOWN = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
New SDK:
public static final String ACTION_REQUEST_SHUTDOWN
= "com.android.internal.intent.action.REQUEST_SHUTDOWN";
The Action value has changed, and the new code is as follows
//shutdown now
String action = "com.android.internal.intent.action.REQUEST_SHUTDOWN";
if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.N){
action = "android.intent.action.ACTION_REQUEST_SHUTDOWN";
}
Intent shutdown = new Intent(action);
shutdown.putExtra("android.intent.extra.KEY_CONFIRM", false);
shutdown.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(shutdown);
finish();
}catch(Exception e){
e.printStackTrace();
}