For what ever reason I can't fix this problem... (Mind you, I have
been messing with it and searching for about 3 hours even though it is
probably really simple)

I have 3 files, my wallpaper class, my wallpapersettings class, and my
wallpapersettings.xml

in my preference file I have:
 <Preference
                        android:title="Background Image"
                        android:summary="Select an Image for the Background"
                        android:key="imagePref" />

in my wallpapersettings class I have: (inside of onCreate)

Preference customPref = (Preference) findPreference("imagePref");
        if(customPref == null)
        {
          customPref = new Preference(getBaseContext());
        }
        customPref.setOnPreferenceClickListener(new
OnPreferenceClickListener()
        {
          public boolean onPreferenceClick(Preference preference)
          {
            /*Toast.makeText(getBaseContext(), "The custom preference
has been clicked", Toast.LENGTH_LONG).show();
            SharedPreferences customSharedPreference =
getSharedPreferences("imagePref", Activity.MODE_PRIVATE);
            SharedPreferences.Editor editor =
customSharedPreference.edit();
            editor.putString("imagePref","The preference has been
clicked");
            editor.commit();
            */
                startActivityForResult(new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 1);

            return true;
          }

        });

and outside of onCreate:

@Override
    public void onActivityResult(int requestCode, int resultCode,
Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == 1)
        if (resultCode == Activity.RESULT_OK) {
          Uri selectedImage = data.getData();
          Log.d("IMAGE SEL", "" + selectedImage);
          // TODO Do something with the select image URI
          SharedPreferences customSharedPreference =
getSharedPreferences("imagePref", Activity.MODE_PRIVATE);
          SharedPreferences.Editor editor = customSharedPreference.edit
();
          editor.putString("imagePref", getRealPathFromURI
(selectedImage));
          Log.d("IMAGE SEL", getRealPathFromURI(selectedImage));
          editor.commit();
        }
    }

in my wallpaper class I have:

String imageBg = mPrefs.getString("imagePref", "Bad Image");
      Bitmap bm;

public void onSharedPreferenceChanged(SharedPreferences prefs, String
key)
      {

          imageBg =  prefs.getString("imagePref", "Bad Image");
          Log.d("CHECK PREF", prefs.getString("imagePref", "wtf"));
          getBackground();
      }

void getBackground()
      {
            File f = new File(Environment.getExternalStorageDirectory(),
imageBg);
            FileInputStream is = null;
            try
            {
              is = new FileInputStream(f);
            }
            catch (FileNotFoundException e)
            {
              Log.d("error: ",String.format( "ShowPicture.java file[%s]
Not Found", imageBg));
              return;
            }
            bm = BitmapFactory.decodeStream(is, null, null);
      }

When my code is ran, I get the correct file path in LogCat from the
wallpapersettings class. (it reports: /sdcard/DCIM/image.jpeg)
However, my wallpaper class says that it cannot find it when I try to
see what my Preference saved. Any one have any idea what im doing
wrong here? if I did not provide enough code for you to help me, let
me know
-- 
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

Reply via email to