以编程方式安装android中的应用程序后,如何检测用户是否单击完成或打开 [英] how to detect if user clicked done or open after application in android has been installed programmatically
本文介绍了以编程方式安装android中的应用程序后,如何检测用户是否单击完成或打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法检测用户是否单击了对话框,该对话框通常在安装 android 应用程序后弹出.这样我就可以继续进行下一个安装或活动.
I'm having trouble detecting if the user clicked the dialog, that usually pops up after the android application has been installed. So that I can proceed to the next installation or activity.
推荐答案
如果我没听错,
- 您正在尝试以编程方式安装 APK
- 您需要获取安装成功后用户按下按钮
Open
或Done
的状态.
- You are trying to programatically install a APK
- You need to get the status, whether the user pressed buttons
Open
orDone
, after the successful installation.
这是可以做到的.为此,请像这样启动软件包安装程序.
This can be done. For this, start the package installer like this.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.fromFile(new File("Full path to your APK")),
"application/vnd.android.package-archive"); // the APK path can be in SDCARD or in your application directory. I am sure you know this path.
// start the package-installer activity and wait for result. The second parameter can be used to identify the source of result in `onActivityResult` method.
startActivityForResult(intent, 1);
- 现在将启动包安装程序,您的 APK 将安装在设备上.
- 用户按下
Open
或Done
按钮. - 您在
onActivityResult
回调函数中重新获得程序控制 - Now the package installer will be started and your APK will get installed on device.
- User presses either
Open
orDone
buttons. - You gets the program control back in
onActivityResult
callback function
onActivityResult
函数:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// requestCode == 1 means the result for package-installer activity
if (requestCode == 1)
{
// resultCode == RESULT_CANCELED means user pressed `Done` button
if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "User pressed 'Done' button", Toast.LENGTH_SHORT).show();
}
else if (resultCode == RESULT_OK) {
// resultCode == RESULT_OK means user pressed `Open` button
Toast.makeText(this, "User pressed 'Open' button", Toast.LENGTH_SHORT).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
这篇关于以编程方式安装android中的应用程序后,如何检测用户是否单击完成或打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文