gpt4 book ai didi

android - ActivityResultLauncher 结果代码始终返回 0 并取消结果

转载 作者:行者123 更新时间:2023-12-05 00:02:40 24 4
gpt4 key购买 nike

试图观察 - 应用程序是否被删除
当我单击确定按钮(删除)时,它返回结果代码 0 取消
与取消按钮相同

 activityResultLaunch = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == RESULT_OK) {
Log.d("tag", "ok");
}
else if(result.getResultCode() == RESULT_CANCELED){
Log.d("tag", "cancelled");
}
else if(result.getResultCode() == RESULT_FIRST_USER){

Log.d("tag", "uninstallfail");
}
}
});
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, uri);

activityResultLaunch.launch(uninstallIntent);

最佳答案

正如@sultan 在评论中指出的那样,这是适用于我以编程方式卸载应用程序的完整代码:

startActivityForResult = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
Log.i("USER CHOSE: ", String.valueOf(result.getResultCode()));

if (result.getResultCode() == RESULT_OK) {
Log.d("TAG", "User accepted the (un)install");
} else if (result.getResultCode() == RESULT_CANCELED) {
Log.d("TAG", "User canceled the (un)install");
} else if (result.getResultCode() == RESULT_FIRST_USER) {
Log.d("TAG", "Failed to (un)install");
}
}
);

String appName = "allrecipes.spinner.free";
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
intent.setData(Uri.parse("package:" + appName));
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
startActivityForResult.launch(intent);

关于android - ActivityResultLauncher 结果代码始终返回 0 并取消结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68697829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com