【问题标题】:How to share text & image in Google Plus (G+) from android without using Intent?如何在不使用 Intent 的情况下从 android 共享 Google Plus (G+) 中的文本和图像?
【发布时间】:2013-03-29 12:06:46
【问题描述】:

我想分享G+. 的人,因为我知道G+ APIFaceBook & Twitter 相同。 我得到this doc 并遵循相同的过程。

我发现我们可以通过两个不同的like来分享,

  • 深度链接
  • 互动帖子

基于此,我必须选择DeepLink 进行分享。

我已经联系到here 但是当我尝试将该代码复制并粘贴到我的new_project 中时,它不起作用。说喜欢

The constructor PlusShare.Builder(Activity) is not visible.

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

请大家帮帮我。

提前致谢

【问题讨论】:

标签: android google-api google-plus


【解决方案1】:
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();

        }
    });

【讨论】:

  • 这依赖于用户安装了 google + 安卓应用。否则这会崩溃。此外,这显然使用了Intents,所以这绝不是这个问题的答案。
  • 我确实有 google+,但仍然无法使用任何想法,请告诉我
猜你喜欢
  • 2012-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-16
相关资源
最近更新 更多