【问题标题】:sharing failed, in api 23, only failed is for whatsapp, after selecting whatsapp from chooser, it returns back to sharer page分享失败,在api 23,只有whatsapp失败,从选择器中选择whatsapp后,返回分享页面
【发布时间】:2016-07-29 06:50:43
【问题描述】:

除了 whatsapp,我的应用程序正在向所有其他应用程序共享内容,例如远足环聊邮件、信使等。 我的编译 sdk 和目标 sdk 是 23

这是我的代码

if (url.startsWith("share://")) {
            Intent share = new Intent(Intent.ACTION_SEND);
            Uri requestUrl = Uri.parse(url);
            String pContent = requestUrl.toString().split("share://")[1];
            String pasteData = pContent+"";
            share.setAction(Intent.ACTION_SEND);
            share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            Toast toast=Toast.makeText(getApplicationContext(),pasteData, Toast.LENGTH_LONG);
            toast.setMargin(50,50);
            toast.show();
            StringBuilder sb = new StringBuilder();
            String [] parts = pasteData.split("<br />");
            for (int i = 0; i < parts.length; i++) {
                String part = parts[i];
                sb.append(part);
                sb.append('\n');
            }
            share.putExtra(android.content.Intent.EXTRA_TEXT, (Serializable) sb);
            share.setType("*/*");
            startActivity(Intent.createChooser(share, "Share On"));
            return true;

让我清楚一点,此代码在所有其他应用程序中都可以正常工作(共享内容),但在 whatsapp 中却不行

我的 logcat 错误

    07-29 12:13:20.068 560-578/? I/ActivityManager: Displayed android/com.android.internal.app.ChooserActivity: +392ms (total +21s340ms)
07-29 12:13:29.337 560-1486/? I/ActivityManager: START u0 {act=android.intent.action.SEND typ=*/* flg=0xb080001 cmp=com.whatsapp/.ContactPicker clip={*/* T: first line content 
                                                  second line content 
                                                  thired line content
                                                  fourth line content
                                                 } (has extras)} from uid 10281 on display 0
07-29 12:13:29.609 9651-9674/com.example.app I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
07-29 12:13:29.609 9651-9674/com.example.app I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
07-29 12:13:29.609 9651-9674/com.example.app I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
07-29 12:13:29.678 30472-30703/? I/MaliEGL: [Mali]window_type=1, is_framebuffer=0, errnum = 0
07-29 12:13:29.678 30472-30703/? I/MaliEGL: [Mali]surface->num_buffers=4, surface->num_frames=3, win_min_undequeued=1
07-29 12:13:29.678 30472-30703/? I/MaliEGL: [Mali]max_allowed_dequeued_buffers=3
07-29 12:13:29.684 560-572/? I/memtrack_graphic: graphic_memtrack_get_memory match 4:      ion_mm_heap 30448  7864320  11 c3f0dc40 de902b00
                                                  : 30448 30448 7864320 11 714938
07-29 12:13:29.716 560-569/? I/art: Background partial concurrent mark sweep GC freed 60007(3MB) AllocSpace objects, 5(100KB) LOS objects, 33% free, 28MB/42MB, paused 2.514ms total 199.165ms
07-29 12:13:37.046 21901-22266/? I/ClearcutLoggerApiImpl: disconnect managed GoogleApiClient

【问题讨论】:

  • 是的,我使用 Intent 方法进行集成,您可以在我的代码中看到。
  • 请仔细检查。 Whatsup 不支持您分享内容的方式。
  • 我根据文档进行了修改,但还是同样的问题,我认为是 sdk 的问题,api23 api 22 问题,请提供高级答案,谢谢。
  • 可能你只是在不同的设备上有不同版本的 whatsup。类似的东西。

标签: android android-sharing


【解决方案1】:

我刚刚得到了答案 我只是改变了

share.setType("text/plain");

而不是share.setType("*/*");

完整代码如下
if (url.startsWith("share://")) { Uri requestUrl = Uri.parse(url); String pContent = requestUrl.toString().split("share://")[1]; // pContent = firstWord <br /> secondWord <br /> ThirdWord Toast toast=Toast.makeText(getApplicationContext(),pContent, Toast.LENGTH_LONG); toast.setMargin(50,50); toast.show(); StringBuilder sb = new StringBuilder(); String [] parts = pContent.split("<br />"); for (int i = 0; i < parts.length; i++) { String part = parts[i]; sb.append(part); sb.append('\n'); } Intent share = new Intent(Intent.ACTION_SEND); share.setAction(Intent.ACTION_SEND); share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); share.putExtra(android.content.Intent.EXTRA_TEXT, (Serializable) sb); share.setType("text/plain"); startActivity(Intent.createChooser(share, "Share On")); return true;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    相关资源
    最近更新 更多