与Messenger或Line分享内容,或其他类似Facebook或Tweeter



嗨,我是新手,可以在Android中开发应用程序。我看到了其他应用程序,它们与Messenger或Facebook的朋友共享。瞬间,我将其分享到Messenger,然后在内容中应显示一些文本和应用程序的链接!我怎样才能做到这一点?任何人请帮忙!!!我已经尝试在此网站中分享答案,但是它仅适用于SMS和Gmail,但是如果我分享给Messenger,它将一无所获!

尝试以链接和文本共享可绘制图像的代码。

请按照此步骤

步骤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 + "nnhttps://www.google.co.in";
            share.putExtra(Intent.EXTRA_TEXT,extraText);
            share.putExtra(Intent.EXTRA_STREAM,
                    Uri.fromFile(f));
            startActivity(Intent.createChooser(share, "Share Image"));

最新更新