2

I am integrating facebook with android and I want when taking a phot , save it to sdcard and then upload it to facebook.

Here is my code:

photo_up=(Button)findViewById(R.id.camera_foto_button);
            photo_up.setOnClickListener(new View.OnClickListener() {
                   public void onClick(View v) {
                       final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
                       intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(PlaceScreen.this)) );   
                       startActivityForResult(intent,CAMERA_REQUEST); 
                   }
                });

 private File getTempFile(Context context){  
          //it will return /sdcard/image.tmp  
          final File path = new File( Environment.getExternalStorageDirectory(), context.getPackageName() );  
          if(!path.exists()){  
            path.mkdir();  
          }  
          return new File(path, "image.png");  
        } 

and the OnActivity Result

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    switch(requestCode){
                case CAMERA_REQUEST:{
                    final File file = getTempFile(this);  
                    try {  
                      bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.fromFile(file) );  
                      // do whatever you want with the bitmap (Resize, Rename, Add To Gallery, etc)  
                    } catch (FileNotFoundException e) {  
                      e.printStackTrace();  
                    } catch (IOException e) {  
                      e.printStackTrace();  
                    }  


                    ByteArrayOutputStream stream = new ByteArrayOutputStream();        
                    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);         
                    byteArray = stream.toByteArray(); // convert camera photo to byte array  
                    Bundle params = new Bundle();       
                    params.putByteArray("picture", byteArray);      
                    params.putString("message", "Have fun");       
                    Utility.mAsyncRunner.request("me/photos", params,
                            "POST", new PhotoUploadListener(), null);
                    break;
                }

So what happens is this: Camera opens, imagae captured and saved but I get a force close and it is not uploaded on fb.

I checked it on my phone,too. Logcat is here:

05-31 02:50:19.437: E/AndroidRuntime(2470): FATAL EXCEPTION: main
05-31 02:50:19.437: E/AndroidRuntime(2470): java.lang.RuntimeException: Unable to resume activity {com.myname.package/com.myname.package.PlaceScreen}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.myname.package/com.myname.package.PlaceScreen}: java.lang.NullPointerException
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2124)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2836)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.access$1600(ActivityThread.java:117)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.os.Looper.loop(Looper.java:130)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.main(ActivityThread.java:3687)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at java.lang.reflect.Method.invokeNative(Native Method)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at java.lang.reflect.Method.invoke(Method.java:507)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at dalvik.system.NativeStart.main(Native Method)
05-31 02:50:19.437: E/AndroidRuntime(2470): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.myname.package/com.myname.package.PlaceScreen}: java.lang.NullPointerException
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2111)
05-31 02:50:19.437: E/AndroidRuntime(2470):     ... 13 more
05-31 02:50:19.437: E/AndroidRuntime(2470): Caused by: java.lang.NullPointerException
05-31 02:50:19.437: E/AndroidRuntime(2470):     at com.myname.package.PlaceScreen.onActivityResult(PlaceScreen.java:325)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.Activity.dispatchActivityResult(Activity.java:3908)
05-31 02:50:19.437: E/AndroidRuntime(2470):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
05-31 02:50:19.437: E/AndroidRuntime(2470):     ... 14 more

edit:

Ok my bmp where is null. Why is that? What ius wrong?

bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.fromFile(file) );  
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 

can anyone find out why my bmp is null while I can see the image in the gallery. That means that image is taken normally but nothing gets as a result of bmp=MediaStore.Images.Media

Abhi
  • 8,935
  • 7
  • 37
  • 60
ghostrider
  • 5,131
  • 14
  • 72
  • 120
  • Exception gives a quite clear hint: something is null at line 325 of PlaceScreen.java. – yorkw May 31 '12 at 00:04
  • Ok my bmp where is null. Why is that? What ius wrong? bmp = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.fromFile(file) ); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); – ghostrider May 31 '12 at 07:16
  • Does your try/catch block surrounding the `getBitmap()` method fire either the `FileNotFoundException` or the `IOException`? Can you verify that file is actually on the SD card at the requested location with DDMS (I know you can see it in the gallery, but that doesn't mean it was saved where you asked it to be saved). – devunwired Jun 07 '12 at 22:31
  • http://stackoverflow.com/faq#bounty – MKJParekh Jun 11 '12 at 09:49
  • sorry it was my first time givin a bounty.. Cheers! – ghostrider Jun 12 '12 at 11:05

1 Answers1

5

While using the generic code available on net to call camera and take photo and retrive it, I faced some problem in SAMSUNG device at that time the same error occured Failure delivering result ResultInfo and couldn't find any solution may be its because of any API Level or Device dependancy.

But to overcome it I wrote my code another way to do the task, The code is here:

1) To Call Camera

        String _path = Environment.getExternalStorageDirectory()
        + File.separator + "TakenFromCamera.png";
        File file = new File(_path);
        Uri outputFileUri = Uri.fromFile(file);
        Intent intent = new Intent(
        android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, 1212);

2) In ActivityResult to get Bitmap

            if (requestCode == 1212) {
                String _path = Environment.getExternalStorageDirectory()
                + File.separator + "TakenFromCamera.png";
                mBitmap = BitmapFactory.decodeFile(_path);
                if (mBitmap == null) {
                    // bitmap still null
                } else {
                    // set bitmap in imageview
                }
            }
MKJParekh
  • 34,073
  • 11
  • 87
  • 98