【问题标题】:Android image request from MySQL来自 MySQL 的 Android 图像请求
【发布时间】:2018-04-05 10:58:30
【问题描述】:

我遇到了一个奇怪的问题,我将图像上传到文件夹并将名称(用户的 id)和扩展名保存在数据库中,并且工作正常,但是当我更改图像时,它在文件夹,但手机中的图像没有改变,尽管我正在编辑保存图像名称和扩展名的 SharedPrefManger。

这是我如何更改文件夹中的图像及其工作正常

    String uploadId = UUID.randomUUID().toString();
    String path = getPath(filepath);

    try {
        new MultipartUploadRequest(this,uploadId,Constants.URL_UPLOADPIC)
                .addFileToUpload(path,"image")
                .addParameter("id",SharedPrefManager.getInstance(this).getKeyUserId())
                .setNotificationConfig(new UploadNotificationConfig())
                .setMaxRetries(2)
                .startUpload();
        String extention =  path.substring(path.lastIndexOf("."));
        String id = SharedPrefManager.getInstance(getApplicationContext()).getKeyUserId();
        SharedPrefManager.getInstance(getApplicationContext()).uploadpicmanager(id+extention);
        Toast.makeText(Profile.this, path, Toast.LENGTH_LONG).show();

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

这里是修改图片名称的上传图片

 public boolean uploadpicmanager(String id){
    SharedPreferences sharedPreferences3 = mCtx.getSharedPreferences(SHARED_PREF_NAME,Context.MODE_PRIVATE);
    SharedPreferences.Editor editor3 = sharedPreferences3.edit();
    editor3.putString(KEY_IMAGE,id);
    editor3.apply();
    return true;
}

这是我如何读取图像及其在第一次上传时工作正常,但是当我更改图片时它不会改变。我想知道如果它不再在文件夹中,它从哪里获取图像??

   Picasso.with(getApplicationContext())
            .load("http://hello.000webhostapp.com/Shop&Go/customers/"+
                    SharedPrefManager.getInstance(getApplicationContext()).getKeyImage())
            .into(profilepic);

【问题讨论】:

    标签: android mysql image


    【解决方案1】:

    可能毕加索会加载图像的缓存版本。

    尝试添加

    .memoryPolicy(MemoryPolicy.NO_CACHE)
    

    在构建器上

    当然这不是一个好习惯,你应该更改图像的路径名(并删除内存策略)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 2021-08-14
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多