从SD卡中的Andr​​oid上传图片至Facebook上传图片、Andr、SD、Facebook

2023-09-06 00:05:28 作者:灵魂被安葬你范畴的王国

我不能够上传影像从SD卡Facebook的...我用低于code ....但它并没有给我的错误,但在同一时间,它没有上传图片

 字节[]数据= NULL;
     尝试 {
         的FileInputStream FIS =新的FileInputStream(文件路径);
         BitmapFactory.Options选项=新BitmapFactory.Options();
            options.inSampleSize = 2;
         位图BI = BitmapFactory.de codeStream(FIS);

         ByteArrayOutputStream BAOS =新ByteArrayOutputStream();
         bi.com preSS(Bitmap.Com pressFormat.JPEG,100,BAOS);
         数据= baos.toByteArray();
      }赶上(FileNotFoundException异常E){
         e.printStackTrace();
         Log.d(的onCreate,调试误差e =+ e.toString());
      }

         捆绑PARAMS =新包();
         params.putString(法,photos.upload);
         params.putByteArray(图片,数据);
 

解决方案

尝试下面摘录从SD卡帖子图片:

将您的图像转换为位图,然后继续

 私人无效postToWall(){
    AsyncFacebookRunner mAsyncRunner =新AsyncFacebookRunner(脸谱);
    ByteArrayOutputStream流=新ByteArrayOutputStream();
    bm.com preSS(Bitmap.Com pressFormat.PNG,100,流); //其中,BM是SD卡位
    字节[]的字节数组= stream.toByteArray();
    捆绑参数=新包();
    参数=新包();
    param.putString(信息,全部);
    param.putString(文件名,考);
    param.putByteArray(形象,字节);
    mAsyncRunner.request(ME /照片,参数,POST,新fbRequestListener(),NULL);
  }

  公共类fbRequestListener实现RequestListener {

      @覆盖
      公共无效的onComplete(字符串响应,对象状态){
          // TODO自动生成方法存根
          Log.d(响应,+响应);

      }

      @覆盖
      公共无效onIOException(IOException异常E,对象状态){
          // TODO自动生成方法存根
          Log.d(响应,+ E);

      }

      @覆盖
      公共无效onFileNotFoundException(FileNotFoundException异常E,
              对象状态){
          // TODO自动生成方法存根
          Log.d(响应,+ E);

      }

      @覆盖
      公共无效onMalformedURLException(MalformedURLException的E,
              对象状态){
          // TODO自动生成方法存根

      }

      @覆盖
      公共无效onFacebookError(FacebookError即对象的状态){
          // TODO自动生成方法存根
          Log.d(响应,+ E);

      }

      }
 

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

     byte[] data = null;
     try {
         FileInputStream fis = new FileInputStream(filepath);
         BitmapFactory.Options options = new BitmapFactory.Options();                   
            options.inSampleSize = 2; 
         Bitmap bi = BitmapFactory.decodeStream(fis);

         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
         data = baos.toByteArray();  
      } catch (FileNotFoundException e) { 
         e.printStackTrace();
         Log.d("onCreate", "debug error  e = " + e.toString());
      }     

         Bundle params = new Bundle(); 
         params.putString("method", "photos.upload");  
         params.putByteArray("picture", data);

解决方案

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

      }

      }