How to share text & image in Google Plus (G+) from android without using Intent?

后端 未结 1 1301
长情又很酷
长情又很酷 2020-12-15 14:28

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.

相关标签:
1条回答
  • 2020-12-15 15:08
    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();
    
            }
        });
    
    0 讨论(0)
提交回复
热议问题