在 onCreate() 方法中使用startActivityForResult
on startActivity
& 发送额外的 1000 作为requestCode
. 您可以在方法内接收该值onActivityResult()
,您可以在方法内显示成功或失败对话框onActivityResult()
,如下所示
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(apkPath)), " application/vnd.android.package-archive");
startActivityForResult(intent, 1000); //1000 is RequestCode here
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check for resultCode == RESULT_OK & requestCode == 1000 conditions
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == 1000) {
System.out.println("Success Status");
} else {
System.out.println("Failure Status");
}
}