Upload image to facebook from SD card in android

前端 未结 2 1790
故里飘歌
故里飘歌 2021-01-26 10:47

I Can\'t able to upload the images on the facebook from SD card...I used below code....but it did not give me error but at the same time it did not upload the images



        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-26 11:50

    Try below Snippet for Post Image from SDCard :

    Convert your image to bitmap and proceed

    private void postToWall() {   
        AsyncFacebookRunner mAsyncRunner = new   AsyncFacebookRunner(facebook);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.PNG, 100, stream);  // where bm is bitmap from Sdcard
        byte[] byteArray = stream.toByteArray();
        Bundle param = new Bundle();
        param = new Bundle();
        param.putString("message", "All");
        param.putString("filename", "TEst");
        param.putByteArray("image", byteArray);
        mAsyncRunner.request("me/photos", param, "POST", new fbRequestListener(), null);
      }
    
      public class fbRequestListener implements RequestListener {
    
          @Override
          public void onComplete(String response, Object state) {
              // TODO Auto-generated method stub
              Log.d("RESPONSE",""+response);
    
          }
    
          @Override
          public void onIOException(IOException e, Object state) {
              // TODO Auto-generated method stub
              Log.d("RESPONSE",""+e);
    
          }
    
          @Override
          public void onFileNotFoundException(FileNotFoundException e,
                  Object state) {
              // TODO Auto-generated method stub
              Log.d("RESPONSE",""+e);
    
          }
    
          @Override
          public void onMalformedURLException(MalformedURLException e,
                  Object state) {
              // TODO Auto-generated method stub
    
          }
    
          @Override
          public void onFacebookError(FacebookError e, Object state) {
              // TODO Auto-generated method stub
              Log.d("RESPONSE",""+e);
    
          }
    
          }
    

提交回复
热议问题