【问题标题】:Updating the profile picture of a user更新用户的个人资料图片
【发布时间】:2013-04-13 23:53:56
【问题描述】:

我正在制作一个应用程序,我正在使用 ImageLoading Framework 从服务器下载图像并将 URL 放入缓存中。现在我想要更新用户的个人资料图片,但即使在服务器上更新了个人资料图片后,它也不会显示在应用程序中。

该应用正在显示用户的旧个人资料照片。为什么会出现这个问题,我该如何解决?

点击更新代码:

update_profile_pic.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
        String value_for_test="delete";
        Toast.makeText(getBaseContext(), "it works", Toast.LENGTH_SHORT).show();
        Intent i=new Intent(getApplicationContext(),ProfilePictureCaptureHomeActivity.class);
        i.putExtra("image",value_for_test);
        startActivity(i);

个人资料图片捕捉首页

DBAdapter db = new DBAdapter(getApplicationContext()); 
db.open();
if (null == phoneNumber) 
{ 
    Cursor c = db.getUserInfo();
    phoneNumber = c.getString(0);
    imageUrl = c.getString(1);
    
    System.out.println("the imageUrl is"+imageUrl);
    c.close(); 
}
setContentView(R.layout.profilepic_capture); 
if (null == imageUrl) 
{ 
    Cursor imageUrlObj = db.getUserInfo();
    imageUrl = imageUrlObj.getString(1);
    System.out.println("the imageurl is"+imageUrl);
    
    imageUrlObj.close(); 
}
db.close();

用于更新头像:

if(image!=null){
    Toast.makeText(getApplicationContext(), "Redirected", Toast.LENGTH_LONG).show();
    imageUrl=null;   
}
if(imageUrl != null)
{
    Intent uploadimg = new Intent(ProfilePictureCaptureHomeActivity.this,ListeningAndSharingHomeActivity.class);
    uploadimg.putExtra("phoneNumber", phoneNumber);
    startActivity(uploadimg);
}
else
{
    Log.v("ProfilePictureCaptureHomeActivity", "Staying Here");
}

_gallerybutton = (ImageButton) findViewById(R.id.btn_gallery);
_photobutton = (ImageButton) findViewById(R.id.btn_photo); 
System.out.println("here in popup phoneeeeee" + phoneNumber); 
System.out.println("here in flag************" + firstUpload);

_gallerybutton.setOnClickListener(new OnClickListener() { 
    @Override
    public void onClick(View v) {
        v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
        System.out.println("here in galleryyyyyyyyyy");
        Intent uploadimg = new Intent(ProfilePictureCaptureHomeActivity.this,ProfilePicFromGallery.class);
        uploadimg.putExtra("phoneNumber", phoneNumber); 
        startActivity(uploadimg);
    }
});

_photobutton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        v.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
        System.out.println("here in take piccccc");
        Intent capIntent = new Intent(ProfilePictureCaptureHomeActivity.this,ProfilePicFromCamera.class);
        startActivity(capIntent);
    }
});
        

【问题讨论】:

  • 你能贴出你的代码 sn-p 吗?
  • 我已经编辑了代码库,请立即查看问题.. 个人资料图片正在更新,但仅在清除缓存之后.. 我已将个人资料图片 url 存储在数据库中 columnindex 1..
  • 您是使用相同的名称保存个人资料图片还是使用不同的名称?
  • 如果您从您的服务器获得相同的个人资料图片名称.. 只需删除本地内存中保存的文件即可。并更新新文件。图像加载器库只会检查文件名..如果退出将显示旧的..它不会下载新图像。
  • 你能告诉我删除本地内存中保存文件的代码吗?我试过 memorycache.clear() 也试过 filecache.clear() 但使用这些应用程序崩溃了。所以请指导我删除你建议的内容......

标签: android sqlite caching image-loading


【解决方案1】:

看看这段代码。

private  String deleteExistingFile(String url , Context context) 
{


    String SaveFolderName = context.getFilesDir().getAbsolutePath()  + "/yourinternalmemoryfolder"; 

    String  str_randomnumber= url.substring(url.lastIndexOf("/") + 1);
    File wallpaperDirectory = new File(SaveFolderName);
        if (!wallpaperDirectory.exists())
        wallpaperDirectory.mkdirs();                
    String  Photo_ImagePath=SaveFolderName+"/" + str_randomnumber ;                 


    String result = "";
    System.out.println("file path to be deleted " + Photo_ImagePath);

         File f = new File(Photo_ImagePath);
          if (f.exists())
          {
              System.out.println(" EEEEEEEEEEXXXXXXXXIIIIISSSSSSSTTTTTTT ");
          try {
            if(f.delete() == true){
                result = "Success";
            }else{
                result = "Failure";
            }

          }

          catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

            return "Error";
        }

          }

          System.out.println("deleting existing file " + result);
        return result;

}

【讨论】:

  • selectBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { showDialog(PROGRESSDIALOG_ID); your code } }); 应用程序崩溃..点击上传配置文件时..
  • 首先删除那个..先尝试使用一些示例删除文件..然后在代码中尝试。
  • 亲爱的 Rajesh 非常感谢 :-) 我在发送到服务器时更改了个人资料图片的名称。因为这对我来说看起来很容易。我用 String uuid = UUID.randomUUID().toString();String filename="image_"+uuid+".png"; :-) 谢谢
  • Ok Alpesh,如果你愿意,我会发布删除特定文件的代码
  • 是的,当然..请张贴。将来对我有用:-)
猜你喜欢
  • 1970-01-01
  • 2017-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-26
  • 1970-01-01
  • 2011-02-14
相关资源
最近更新 更多