< CS193A Android Programming

For today I'll added some features and published the app Baby Picture Fun: (you can see how the package path is the unique id of the app in the url there). Alternately, here is a link to the raw .apk file on this server: BabyPictureFun.apk (you can install on a Kindle Fire via this link).

Intent with Result, Code Write to Preferences

    public void selectImage() {
    	// Switches to the gallery browser for the user to select an image.
    	Intent intent = new Intent();
    	startActivityForResult(Intent.createChooser(intent, getString(R.string.selectmain)), 1);

    // Called with result of activity
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    	if (resultCode == RESULT_OK) {
    		if (requestCode == 1) {
    			Uri uri = data.getData();  // get data back from gallery, pointing to image in fs

    // Sets the uri of the image to use + saves that uri as a preference.
    public void setMainImage(Uri uri) {
    	// save as pref
    	SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    	SharedPreferences.Editor ed = prefs.edit();
    	ed.putString("imageuri", uri.toString());
    	ed.commit();  // apply() in 2.3

    	// send to the view

    // In the monkey class, get the bitmap from the uri like this
    // Bitmap bitmap = Media.getBitmap(mContext.getContentResolver(), imageUri);
    // mMain = makeScaled(bitmap, 160 * mScale);

    // According to blogs I saw, the above may crash with low-memory
    // if the image is very large, but it worked for me on all hardware.

Going To The Market

Crash Course on Certificates

Putting on the Market

App Strategy Ideas