5

I am making an application where I am using ImageLoading Framework for downloading the images from the server and put the URLs in the cache. Now I want the user's profile picture updating but even after updation of the profile pic on the sever it's not displaying in the application.

The app is showing the old profile pic of the User. Why this problem is arising and how can I troubleshoot?

Code for update onclick:

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);

Profile Pic CaptureHome

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();

for updating the profile picture:

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);
    }
});
        
halfer
  • 19,824
  • 17
  • 99
  • 186
Alpesh
  • 265
  • 2
  • 7
  • 22
  • can you post your code snippet ? – itsrajesh4uguys Apr 22 '13 at 05:23
  • I have edited the code base please see the issue now.. The Profile pic is being updated but only after clearing the cache.. I have stored the Profilepic url in the database at columnindex 1.. – Alpesh Apr 22 '13 at 06:27
  • you are using same name for profile picture to save or different names ? – itsrajesh4uguys Apr 22 '13 at 06:29
  • 1
    if you will get the same name for profile picture from your server .. just delete the saved file in your local memory. and update the new file. image loader library will just check for the file name ..if exits that will show the old one.. and it wont download the new image. – itsrajesh4uguys Apr 22 '13 at 06:34
  • Can you plz tell me the code for delete the saved file in my local memory.. I tried memorycache.clear() and also tried filecache.clear() but using these the app is crashing..so plz guide me to delete the same you suggesed... – Alpesh Apr 22 '13 at 07:04
  • You are right.. when i am changing the name of the Profile pic its working but i need the same name format which i have used so plz help me to delete the saved file on local memory... I have used code for update profile pic but before i am not able to delete the saved file on local memory..so help me for that ...how can i do that... – Alpesh Apr 22 '13 at 07:14

1 Answers1

0

have a look at this code.

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;

}
itsrajesh4uguys
  • 4,610
  • 3
  • 20
  • 31
  • `selectBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { showDialog(PROGRESSDIALOG_ID); your code } });` app is crashing..when clicked to upload the profile piture.. – Alpesh Apr 22 '13 at 08:40
  • first remove that .. just try to delete the file using some sample first.. then try it in code. – itsrajesh4uguys Apr 22 '13 at 09:32
  • Dear Rajesh thanks alot :-) I did it with the changing the name of the profile pic when sending to the server.. because it looks easy to me. I did it with String uuid = UUID.randomUUID().toString();String filename="image_"+uuid+".png"; :-) thanks – Alpesh Apr 23 '13 at 11:41
  • Ok Alpesh, if you want i will post the code to delete the particular file – itsrajesh4uguys Apr 23 '13 at 12:06
  • Yeah sure.. please post it. It will be useful for me in future :-) – Alpesh Apr 23 '13 at 12:35