我怎么能存储的图像使用共享preference android系统中?图像、系统、我怎么能、preference

由网友(就算全世界与我为敌)分享简介:我要保存图像的机器人使用共享preference。我有两个活动课,当我点击第一个活动的按钮,它会调用第二个活动,第二个活动显示我的$ P $列表视图pferred名,并且也重置了Android墙纸,我已经设置为$图像p $ pferred壁纸的第一个活动。I want to save images in andro...

我要保存图像的机器人使用共享preference。我有两个活动课,当我点击第一个活动的按钮,它会调用第二个活动,第二个活动显示我的$ P $列表视图pferred名,并且也重置了Android墙纸,我已经设置为$图像p $ pferred壁纸的第一个活动。

I want to save images in android using sharedpreference. I have two activity classes, when i click the button of first activity it will call the second activity and second activity displays my preferred name in a list view and also resets the android wallpaper to the image that I had set as a preferred wallpaper in the first activity.

对于第二个活动code是:

For the second activity the code is:

public class PreferencesActivityTest extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


            SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
            String prefName = myPrefs.getString("PREF_USERNAME", "nothing");
            String wallPaper = myPrefs.getString("PREFS_NAME", null);


            if(wallPaper != null) {

                try {

                      Bitmap bm = BitmapFactory.decodeFile("/data/misc/wallpaper/"+wallPaper);
                      Log.d(getClass().getSimpleName(),"Wallpaper name is: "+ wallPaper);
                      setWallpaper(bm);
                      Toast.makeText(this, "Wall paper has been changed." +
                                  "You may go to the home screen to view the same", Toast.LENGTH_LONG).show();
                } 

                catch (FileNotFoundException fe){
                      Log.e(getClass().getSimpleName(),"File not found");
                } catch (IOException ie) {
                      Log.e(getClass().getSimpleName()," IO Exception");
                }

    }


        ArrayList<String> results = new ArrayList<String>();
        results.add("Your Preferred name is: " + prefName);
      this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));
    }

第一个活动调用第二个活动,但他并没有叫如果(壁纸!= NULL){}

为什么不工作?

推荐答案

它不是在分享preferences推荐店铺形象你应该存储图像sdcard.And然后存储图像路径(从SD卡)为共享preferences这样的 -

Its not recommended to store image in Share preferences And you should store that image to sdcard.And then store image path (from sdcard) into Share preferences like this--

    SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
    Editor edit=shre.edit();
    edit.putString("imagepath","/sdcard/imh.jpeg");
    edit.commit();

,然后通过这条道路,从取SD卡图像

and then fetch image from sdcard by using this path

阅读全文

相关推荐

最新文章