【问题标题】:Whats app sending message via href link and fallback for users without appWhats app 通过 href 链接发送消息并为没有应用程序的用户回退
【发布时间】:2016-09-15 16:27:36
【问题描述】:

我正在开发一个社交页面,该页面允许用户选择一个链接,该链接将打开 whatsapp 并向用户选择的联系人发送消息。

我目前正在这样做,如下所示。

<a class="modal__link modal__link--whatsapp js-product-share__link--wa"
               href="whatsapp://send?text=<?php echo $whatsappBody . " " . $currentUrl;?>" data-action="share/whatsapp/share">

此方法同时支持 IOS 和 Android。但是我的问题是,如果以太设备上没有安装 whatsapp,我只会收到一条通用错误消息。

理想情况下,我希望能够将用户重定向到适当的商店以下载 whatsapp。

任何人都可以深入了解当前的回退方法是什么吗?

【问题讨论】:

    标签: android ios whatsapp deep-linking fallback


    【解决方案1】:
      boolean installed = appInstalledOrNot("com.whatsapp");
    
    if(installed){
    // do your task
    }else{
    try {
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + "com.whatsapp"));
        i.addFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);
    } catch (android.content.ActivityNotFoundException anfe) {
        ...
    }
    }
    
    
     private boolean appInstalledOrNot(String uri) {
                PackageManager pm = getPackageManager();
                boolean app_installed;
                try {
                    pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
                    app_installed = true;
                }
                catch (PackageManager.NameNotFoundException e) {
                    app_installed = false;
                }
                return app_installed;
            }
    

    试试这个,让我知道它是否有效

    【讨论】:

    • 如果它对您有用,请接受正确的答案,如果不正确,请告诉我,以便我可以在上面找到其他内容
    • 请原谅我对此一无所知,但这仅与应用程序开发有关,而不是在浏览器中引用应用程序时?
    • 如果你想在浏览器上引用,那么你可以在 activitynotfoundexception 中添加这个,或者如果你确实想在浏览器上发送,那么直接添加这个而不是 Uri.parse("market://details?id= " + "com.whatsapp") startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("play.google.com/store/apps/details?id=com.whatsapp")));
    猜你喜欢
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 2021-08-30
    • 1970-01-01
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多