如何检测,如果用户单击做过或开放后的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
- 您需要得到的地位,无论是用户pressed按钮
打开
或完成
,后安装成功。
- 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将得到安装在设备上。
- 用户presses无论是
打开
或完成
按钮。 - 您得到程序控制回
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);
}
else if (resultCode == RESULT_OK) {
// resultCode == RESULT_OK means user pressed `Open` button
Toast.makeText(this, "User pressed 'Open' button", Toast.LENGTH_SHORT);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
这篇关于如何检测,如果用户单击做过或开放后的Android应用程序已经安装编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文