简体   繁体   English

如何检测用户点击完成或在Android中的应用程序之后打开已经以编程方式安装

[英]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, 如果我找到你,

  • You are trying to programatically install a APK 您正在尝试以编程方式安装APK
  • You need to get the status, whether the user pressed buttons 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);
  • Now the package installer will be started and your APK will get installed on device. 现在,程序包安装程序将启动,您的APK将安装在设备上。
  • User presses either Open or Done buttons. 用户按下“ OpenDone按钮。
  • You gets the program control back in 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.

相关问题 Android设备如何检测已安装应用程序? - How does an Android device detect that an app has already been installed? 安装Android应用程序后如何运行代码? - How do you run code after an Android application has been installed? 如何检测我的 Android 应用程序是否已使用 AndroidJUnitRunner 启动? - How to detect if my Android application has been started using AndroidJUnitRunner? 在单击后禁用按钮,Android - Disable a button after is has been clicked, android React Native - 如果应用程序 Y 已安装,如何应用程序 X 打开应用程序 Y - React Native - How to Application X open Application Y if Application Y has been installed 单击单选按钮后,如何创建警报对话框提示用户输入用户名和密码(Android)? - How can i create an alert dialog to prompt user for username and password after a radio button has been clicked (Android)? 如何从网站上检测用户是否拥有移动应用程序并打开该应用程序 - How to detect if the user has the mobile application from a website and open the app 检测是否在Android WebView中单击了特定按钮 - Detect if a specific button has been clicked in Android WebView 如何检测单击了列表视图项的位置(列)(android)? - How to detect the place (column) where a list-view item has been clicked (android)? 如何测试Facebook用户是否已使用sdk 3安装了我的android应用程序 - How to test if a Facebook user has installed my android application with sdk 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM