【问题标题】:Share content to Messenger or Line or other like Facebook or Tweeter将内容分享到 Messenger 或 Line 或其他 Facebook 或 Tweeter
【发布时间】:2016-12-10 06:00:01
【问题描述】:

您好,我是在 android 中开发应用程序的新手。 我看到其他应用程序,他们使用 Messenger 或 Facebook 分享给朋友。 瞬间,我把它分享到 Messenger,然后在内容中应该显示一些文本和应用程序的链接! 我怎样才能做到这一点?任何人请帮助! 我已经尝试在这个网站上分享答案,但它只适用于 SMS 和 Gmail,但如果我分享到 Messenger,它什么也没有显示!

【问题讨论】:

    标签: android facebook android-studio facebook-messenger messenger


    【解决方案1】:

    试试这个代码来分享带有链接和文本的可绘制图像。

    按照这些步骤操作

    第 1 步:-在您的 layout.xml 中单击一个按钮以分享您的内容。

    第 2 步:- 在您的 Activity.java 中为此按钮设置 onClickListner

    第 3 步:- 将此代码放入您的Activity.java 文件按钮setOnClickListner

    String myText = "share text though this string";
                Bitmap icon = BitmapFactory.decodeResource(getResources(),
                        R.mipmap.icon_256);
                Intent share = new Intent(Intent.ACTION_SEND);
                share.setType("image/jpg");
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
                File f = new File(Environment.getExternalStorageDirectory()
                        + File.separator + "temporary_file.jpg");
                try {
                    f.createNewFile();
                    FileOutputStream fo = new FileOutputStream(f);
                    fo.write(bytes.toByteArray());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String extraText = myText + "\n\nhttps://www.google.co.in";
                share.putExtra(Intent.EXTRA_TEXT,extraText);
                share.putExtra(Intent.EXTRA_STREAM,
                        Uri.fromFile(f));
                startActivity(Intent.createChooser(share, "Share Image"));
    

    【讨论】:

    • 非常感谢!!!但我仍然想知道是否可以从我的应用程序创建图像到手机存储上的文件夹,然后通过获取它的 uri 来共享它。我该怎么做?
    猜你喜欢
    • 2014-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多