【问题标题】:Send URL/link with custom scheme through WhatsApp通过 WhatsApp 发送带有自定义方案的 URL/链接
【发布时间】:2016-08-27 02:47:45
【问题描述】:

我需要通过 WhatsApp 发送带有自定义方案的 url(myapp://app.myapp.com/data)。但在 WhatsApp 中,它没有显示自定义方案(myapp://) 作为链接。只有app.myapp.com/data 显示为链接。 我试过下面的代码:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT,"Please check this link: "+Html.fromHtml("myapp://app.myapp.com/data"));
            intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "Select Chooser to send friend"));

是否可以在android平台的WhatsApp上发送带有自定义方案的链接?

【问题讨论】:

  • 在提问时尝试添​​加一些代码
  • 请添加您的代码
  • 您不能使用这种类型的自定义方案,因为 whatsapp 无法将其识别为 Url。它只识别带有“http://”或“https://”前缀的网址。
  • @Damini:android WhatsApp 中是否有任何参考不支持自定义方案。因为我们可以在 iOS 中使用自定义方案。
  • @Jai:检查此参考:stackoverflow.com/questions/2430045/…

标签: android android-intent whatsapp custom-url custom-scheme-url


【解决方案1】:

试试这个代码:

 Whatsappbutton.setOnClickListener(new OnClickListener() {

            @SuppressLint("NewApi") @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                try {
                    Tracker t = ((Analytics) getActivity().getApplication())
                            .getTracker(TrackerName.APP_TRACKER);

                    t.send(new HitBuilders.EventBuilder()
                            .setCategory(getString(R.string.ic_Category))
                            .setAction(getString(R.string.ic_action))
                            .setLabel(getString(R.string.ic_labelwhatsapp)).build());
                } catch (Exception e) {
                    Toast.makeText(getActivity().getApplicationContext(),
                            "Error" + e.getMessage(), 1).show();
                }
                Toast.makeText(getActivity(), R.string.invite_friends_toast_after_share, Toast.LENGTH_LONG).show();

                final String shareBody = getResources().getString(R.string.invite_friends_market_url);
                try {
                    Intent shareToWhatsApp = new Intent(Intent.ACTION_SEND);
                    shareToWhatsApp.setType("text/plain");



       shareToWhatsApp.putExtra(android.content.Intent.EXTRA_TEXT, 

       shareBody);

                    shareToWhatsApp.setClassName("com.whatsapp",  

                   "com.whatsapp.ContactPicker");
                    startActivity(shareToWhatsApp);
                } catch (Exception e) {
                    Intent shareGeneric = new Intent(Intent.ACTION_SEND);
                    shareGeneric.setType("text/plain");
                    shareGeneric.putExtra(android.content.Intent.EXTRA_TEXT, 

                    shareBody);

                    startActivity(Intent.createChooser(shareGeneric,    
   getResources().getString(R.string.invite_friends_share_chooser)));
                }

            }
        });

【讨论】:

  • 让我知道它是否有用?
  • 它不起作用。仍然 myapp:// 部分未显示为链接
猜你喜欢
  • 1970-01-01
  • 2014-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-22
  • 1970-01-01
  • 2013-07-31
  • 1970-01-01
相关资源
最近更新 更多