本文介绍了如何分享文字 &在不使用 Intent 的情况下从 android 使用 Google Plus (G+) 中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我想在 G+ 中分享. 据我所知,G+ APIFaceBook & 相同.推特.我收到此文档 并遵循相同的流程.

Guys i want to share in G+. As i knew there are G+ API same as FaceBook & Twitter.I get this doc and follow the same process.

我发现我们可以通过两种不同的方式分享,

I have found that we can share via two different like ,

  • 深度链接
  • 互动帖子

基于此,我必须选择 DeepLink 进行共享.

and base on that i have to choose DeepLink for sharing.

我已经到了这里但是当我尝试将该代码复制并粘贴到我的 new_project 中时,它不起作用.说喜欢

i have reach up to herebut when i try to copy and paste that code in my new_project then its not working. says like

构造函数 PlusShare.Builder(Activity) 不可见.

我找到了很多,但最后我得到了相同的 API 链接.不知道如何完成这个任务.我已经在 FaceBook & 分享过了Twiiter 但在 G+ 中没有取得成功.

I found a lot but at the end i get same API link. Don't know how to achieve this task.I have done sharing in FaceBook & Twiiter but not get success in G+.

请大家帮帮我.

提前致谢

推荐答案

public void share_image_text_GPLUS() {
    File pictureFile;

    try {
        File rootSdDirectory = Environment.getExternalStorageDirectory();

        pictureFile = new File(rootSdDirectory, "attachment.jpg");
        if (pictureFile.exists()) {
            pictureFile.delete();
        }
        pictureFile.createNewFile();

        FileOutputStream fos = new FileOutputStream(pictureFile);

        URL url = new URL("http://img.youtube.com/vi/AxeOPU6n1_M/0.jpg");
        HttpURLConnection connection = (HttpURLConnection) url
                .openConnection();
        connection.setRequestMethod("GET");
        connection.setDoOutput(true);
        connection.connect();
        InputStream in = connection.getInputStream();

        byte[] buffer = new byte[1024];
        int size = 0;
        while ((size = in.read(buffer)) > 0) {
            fos.write(buffer, 0, size);
        }
        fos.close();

    } catch (Exception e) {

        System.out.print(e);
        // e.printStackTrace();
        return;
    }

    Uri pictureUri = Uri.fromFile(pictureFile);

    Intent shareIntent = ShareCompat.IntentBuilder.from(this)
            .setText("Hello from Google+!").setType("image/jpeg")
            .setStream(pictureUri).getIntent()
            .setPackage("com.google.android.apps.plus");
    startActivity(shareIntent);
}

    buttonLoadImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            share_image_text_GPLUS();

        }
    });

这篇关于如何分享文字 &在不使用 Intent 的情况下从 android 使用 Google Plus (G+) 中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 19:23