我希望你能提供帮助。我无法在任何地方找到任何相关文档。 我在Android应用程序WRITE_EXTERNAL_STORAGE中请求运行时权限。
在Android M下,这可以正常工作。我点击了'允许'一切都很好。 在Android N下,点击'允许'杀了我的应用程序。它没有崩溃,只是停止了。
在logcat中显示
Killing 6599:com.myname.myappname/u0a223 (adj 100): permission grant or revoke changed gids
Force removing ActivityRecord{c834991 u0 com.myname.myappname/.MainActivity t1814}: app died, no saved state
Destroying surface Surface(name=Window{bf01619 u0 com.myname.myappname/com.myname.myappname.MainActivity}) called by com.android.server.wm.WindowStateAnimator.destroySurface:-1 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:-1 com.android.server.wm.WindowState.removeLocked:-1 com.android.server.wm.WindowManagerService.removeWindowInnerLocked:-1 com.android.server.wm.WindowManagerService.removeWindowLocked:-1 com.android.server.wm.WindowManagerService.removeWindowLocked:-1 com.android.server.wm.AppWindowToken.removeAllWindows:-1 com.android.server.wm.AppWindowToken.removeAppFromTaskLocked:-1
查看Android源代码,我发现许可授予或撤销已更改的gids'在PackageManagerService.java中
private static final String KILL_APP_REASON_GIDS_CHANGED = "permission grant or revoke changed gids";
和
final int result = permissionsState.grantRuntimePermission(bp, userId);
switch (result) {
case PermissionsState.PERMISSION_OPERATION_FAILURE: {
return;
}
case PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED: {
mHandler.post(new Runnable() {
@Override
public void run() {
killSettingPackagesForUser(sb, userId, KILL_APP_REASON_GIDS_CHANGED);
}
});
我以前运作良好的应用代码是:
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
然后
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
if (requestCode == 1) {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// do stuff
}
有人可以向我解释为什么该应用程序被杀?并且可能如何捕获它以便以编程方式重新启动应用程序?