I've got this code to work but I get the feeling that I'm doing it the
sloppy way and I'd much rather do this right.
I've got a Preference that when clicked is supposed to
startActivityForResult.
The activity to be opened is a gallery of images in the camera folder
"/sdcard/dcim/Camera/".
When the folder exists everything is fine. When the folder doesn't
exist the code fails on the line calling startActivityForResult.
I got things running by checking for the existence of the folder
before starting the second activity.
But I'm still not sure why I can check for the existence of the folder
in the activity with the preference and not in the activity with the
image gallery.
Is there a proper way to go about this?
----Preference that opens image gallery on click----------
mypreferencename.setOnPreferenceClickListener(new
OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference arg0) {
Context context = getApplicationContext();
--start the hack that makes this work---
File cameraDir = new File("/sdcard/dcim/Camera/");
if(cameraDir.exists()==false){
Toast.makeText(context, "No SD Card
attached or camera has taken
no pictures.", Toast.LENGTH_LONG).show();
return false;
}
---end the hack that makes this work----
Intent mIntent = new Intent();
mIntent.setClass(context,
ImageSwitcherWrapper.class);
startActivityForResult(mIntent, CHANGE_PIC);
return true;
}
});
preferenceScreen.addPreference(catPic);
---first few lines of the onCreate of the imageSwicherWrapper---
public class ImageSwitcherWrapper extends Activity implements
AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory {
private File[] mImageIds;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File cameraDir = new File("/sdcard/dcim/Camera/");
if(cameraDir.exists()==false){
Toast.makeText(this, "No SD Card attached or camera has
taken no
pictures.", Toast.LENGTH_LONG).show();
return;
}
//load images
mImageIds = cameraDir.listFiles();
---etc---
--
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