如何共享文本和放大器;图像中的谷歌加(G +)的机器人,而无需使用意图是什么? [英] How to share text & image in Google Plus (G+) from android without using Intent?

查看:158
本文介绍了如何共享文本和放大器;图像中的谷歌加(G +)的机器人,而无需使用意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

家伙,我想分享 G +。,因为我知道有 G + API 一样 Facebook和放大器;微博。 我得到这个文档并遵循相同的过程。

我发现,我们可以通过两个不同的共享一样,

  • 深层链接
  • 互动帖

和立足,我必须选择 DeepLink 共享。

我有高达这里 但是当我试图复制并粘贴code在我的 NEW_PROJECT 然后它不工作。说,像

构造PlusShare.Builder(活动)是不可见的

我找到了很多,但最后我得到相同的API链接。不知道如何实现这一任务。 我已经做了Facebook和放共享; Twiiter但没有得到G +的成功。

请专家帮我。

在此先感谢

解决方案

 公共无效share_image_text_GPLUS(){
    PictureFile的文件;

    尝试 {
        文件rootSdDirectory = Environment.getExternalStorageDirectory();

        PictureFile的=新的文件(rootSdDirectory,attachment.jpg);
        如果(pictureFile.exists()){
            pictureFile.delete();
        }
        pictureFile.createNewFile();

        FileOutputStream中FOS =新的FileOutputStream(PictureFile的);

        网址URL =新的URL(http://img.youtube.com/vi/AxeOPU6n1_M/0.jpg);
        HttpURLConnection的连接=(HttpURLConnection类)网址
                .openConnection();
        connection.setRequestMethod(GET);
        connection.setDoOutput(真正的);
        connection.connect();
        在的InputStream = connection.getInputStream();

        byte []的缓冲区=新的字节[1024];
        INT大小= 0;
        而((大小= in.read(缓冲液))大于0){
            fos.write(缓冲液,0,大小);
        }
        fos.close();

    }赶上(例外五){

        System.out.print(E);
        // e.printStackTrace();
        返回;
    }

    乌里pictureUri = Uri.fromFile(PictureFile的);

    意图shareIntent = ShareCompat.IntentBuilder.from(本)
            .setText(你好,从谷歌+!)。的setType(为image / jpeg)
            .setStream(pictureUri).getIntent()
            .setPackage(com.google.android.apps.plus);
    startActivity(shareIntent);
}

    buttonLoadImage.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            share_image_text_GPLUS();

        }
    });
 

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 ,

  • Deep linking
  • Interactive posts

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

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

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

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+.

Please Guys help me.

Thanks in advance

解决方案

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();

        }
    });

这篇关于如何共享文本和放大器;图像中的谷歌加(G +)的机器人,而无需使用意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆