Hi,
I get NPE's for a Uri in the callback in onActivityResult I
instantiate on launching the on-board camera activity ONLY WHEN the
Nexus One (2.2) is used to take a photo in landscape orientation.
public class Photo_Activity extends Activity {
private final static int TAKE_PHOTO = 2;
private Intent cameraIntent;
private Uri takenPhotoUri;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll =
(LinearLayout)findViewById(R.id.message_layout);
cameraIntent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Button launchCam = new Button(this);
launchCam.setText("Take a photo now");
ll.addView(launchCam);
launchCam.setOnClickListener(new
View.OnClickListener() {
public void onClick(View v) {
ContentValues values = new
ContentValues();
String filename =
String.valueOf(System.currentTimeMillis()) ;
values.put(Images.Media.TITLE,
filename);
values.put(Images.Media.DATE_ADDED,
System.currentTimeMillis());
values.put(Images.Media.MIME_TYPE,
"image/
jpeg");
takenPhotoUri =
Photo_Activity.this.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI,
values);
Photo_Activity.this.cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
takenPhotoUri);
startActivityForResult
(Photo_Activity.this.cameraIntent, Photo_Activity.TAKE_PHOTO);
}
});
}
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent); //
intent is null
switch(requestCode) {
case TAKE_PHOTO:
if (resultCode == RESULT_OK) {
Log.d(TAG, "takenPhotoUri: "+
Photo_Activity.this.takenPhotoUri.toString()); //NPE HERE when
photo taken in landscape orientation
}
break;
}
}
}
A workaround is to instantiate the Uri in onCreate(), but if the user
then does not proceed to take a photo from this activity (e.g. does
not press the button "launch camera", presses HOME etc.) an empty jpeg
is created on the SD card and shown in the gallery, which is ugly and
cluttering.
Has anyone seen this before? What is the recommended workaround? I
would say this is a bug. Report it?
Thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en