How to Share Image using Facebook android

前端 未结 3 1552
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 01:13

I am trying to share Image and Content via Facebook,but what i am trying is if user is not logged in via Facebook,and user click on Share button then first it should ask for

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-20 01:16

    You need to call below code on click of button from adapter.

    List permissionNeeds = Arrays.asList("publish_actions");
    
    		manager = LoginManager.getInstance();
    
    		manager.logInWithPublishPermissions(this, permissionNeeds);
    
    		manager.registerCallback(callbackManager,
    				new FacebookCallback() {
    					@Override
    					public void onSuccess(LoginResult loginResult) {
    						publishImage();
    
    					}
    
    					@Override
    					public void onCancel() {
    						System.out.println("onCancel");
    					}
    
    					@Override
    					public void onError(FacebookException exception) {
    						System.out.println("onError");
    					}
    				});
    
    	}
    
    
        private void publishImage() {
    		Bitmap image = BitmapFactory.decodeResource(getResources(),
    				R.drawable.ic_launcher);
    
        //You need to get bitmap from any source.
    
    		SharePhoto photo = new SharePhoto.Builder().setBitmap(image)
    				.setCaption("Welcome To Facebook Photo Sharing on steroids!")
    				.build();
    
    		SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(
    				photo).build();
    
    		ShareApi.share(content, null);
    		Toast.makeText(this, "Succsesfully posted on your wall",
    				Toast.LENGTH_LONG).show();
    
    	}

提交回复
热议问题