Answer the question
In order to leave comments, you need to log in
How to fix failed to make and chown /acct/uid_10058: Read-only file system error?
I'm doing the code according to the example , but I can't write the file and read it. The application does not crash, just an empty activity.
Here is the code:
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Picasso.with(this).load("http://traderex.ru/wp-content/uploads/2017/09/1-768x408.png").into(picassoImageTarget(getApplicationContext(), "imageDir", "page1.png"));
ContextWrapper cw = new ContextWrapper(getApplicationContext());
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
File myImageFile = new File(directory, "page1.png");
ImageView iView = (ImageView)findViewById(R.id.imageView);
try {
Picasso.with(this).load(myImageFile).into(iView);
} catch (Exception e) {
e.printStackTrace();
}
// Picasso
// .with(getApplicationContext())
// .load("http://human-factors.ru/todbook/book_1/pages/page1.png")
// .into(iView);
}
private Target picassoImageTarget(Context context, final String imageDir, final String imageName) {
Log.d("picassoImageTarget", " picassoImageTarget");
ContextWrapper cw = new ContextWrapper(context);
final File directory = cw.getDir(imageDir, Context.MODE_PRIVATE); // path to /data/data/yourapp/app_imageDir
return new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
new Thread(new Runnable() {
@Override
public void run() {
final File myImageFile = new File(directory, imageName); // Create image file
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myImageFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Log.i("image", "image saved to >>>" + myImageFile.getAbsolutePath());
}
}).start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
if (placeHolderDrawable != null) {}
}
};
}
}
Answer the question
In order to leave comments, you need to log in
Found the solution here .
Deleted all devices via AVD Manager, created a new device. The error is gone
This is not the only tutorial on how to save an image to disk using Picasso. Maybe people don't have time to search, the error is in you or in the tutorial. You can try other variants of the code of the same logic and localize the error, i.e. understand the error in the code or in something else (for example, in write permissions). For example, here is another tutorial with slightly different code. Try it and see if the error is gone. At worst, the third option.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question