[英]how to detect if user clicked done or open after application in android has been installed programmatically
I'm having trouble detecting if the user clicked the dialog, that usually pops up after the android application has been installed. 我无法检测用户是否点击了安装Android应用程序后通常会弹出的对话框。 So that I can proceed to the next installation or activity.
这样我就可以进行下一次安装或活动了。
You can't detect that. 你无法检测到。
If you are wanting to do some operation on the first run of the application then just store a "first run" flag within your user preferences and default it to true. 如果您想在第一次运行应用程序时执行某些操作,则只需在用户首选项中存储“首次运行”标志,并将其默认为true。
You can then check this on start of your app and perform any necessary operations. 然后,您可以在应用程序启动时检查此项并执行任何必要的操作。
Some example code for this; 一些示例代码;
private boolean prefFirstRun;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
settings = PreferenceManager.getDefaultSharedPreferences(this);
prefFirstRun= settings.getBoolean("FirstRun", true);
}
@Override
protected void onStart() {
super.onStart();
if (prefFirstRun) {
prefFirstRun = false;
// Do your initial operations here
}
}
@Override
protected void onStop() {
super.onStop();
SharedPreferences settings = PreferenceManager
.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("FirstRun", false);
editor.commit();
}
If i get you correctly, 如果我找到你,
Open
or Done
, after the successful installation. Open
还是Done
按钮。 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);
Open
or Done
buttons. Open
或Done
按钮。 onActivityResult
callback function onActivityResult
回调函数中获得程序控制 Here goes the onActivityResult
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.