How to share image in google Plus through an android app?

前端 未结 6 1747
既然无缘
既然无缘 2020-12-24 07:54

I have already tried this code, but i didn\'t saw photo shared in my account.

File file = new File(\"sdcard/1346249742258.jpg\");
String photoUri = null;
pho         


        
6条回答
  •  遥遥无期
    2020-12-24 08:35

    You can share image using below api's. For detailed steps check tutorial

    http://androidsrc.net/integrating-google-plus-sign-in-into-your-android-application/

     /**
         * API to process media post request start activity with MIME type as video
         * and image
         */
        private void processShareMedia() {
            Intent photoPicker = new Intent(Intent.ACTION_PICK);
            photoPicker.setType("video/*, image/*");
            startActivityForResult(photoPicker, PICK_MEDIA_REQUEST_CODE);
    
        }
    
    /**
     * Handle results for your startActivityForResult() calls. Use requestCode
     * to differentiate.
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PICK_MEDIA_REQUEST_CODE) {
            // If picking media is success, create share post using
            // PlusShare.Builder
            if (resultCode == RESULT_OK) {
                Uri selectedImage = data.getData();
                ContentResolver cr = this.getContentResolver();
                String mime = cr.getType(selectedImage);
    
                PlusShare.Builder share = new PlusShare.Builder(this);
                share.setText("Hello from AndroidSRC.net");
                share.addStream(selectedImage);
                share.setType(mime);
                startActivityForResult(share.getIntent(),
                        SHARE_MEDIA_REQUEST_CODE);
            }
        }
    }
    

提交回复
热议问题