You're giving this FileNotFoundException error, when I change the photo on android
W / System.err: java.io.FileNotFoundException: limit.jpg W / System.err:
at android.content.res.AssetManager.openAsset (Native Method) at android.content.res.AssetManager.open (AssetManager.java:374) W / System.err: at android.content.res.AssetManager.open (AssetManager.java:348) at com.example.luiz.teacherassistent.Interface.CadastroQuestao.CadastrarResolucao.getTestFile (RegisterResolucao.java:235) at com.example.luiz.teacherassistent.Interface.CadastroQuestao.CadastrarResolucao.setTextViews (RegadaResolucao.java:159) at com.example.luiz.teacherassistent.Interface.CadastroQuestao.CadastrarResolucao.onActivityResult (RegisterResolucao.java:141) at android.app.Activity.dispatchActivityResult (Activity.java:7276) at android.app.ActivityThread.deliverResults (ActivityThread.java:4264) at android.app.ActivityThread.handleSendResult (ActivityThread.java:4312) at android.app.ActivityThread.-wrap19 (Unknown Source: 0) at android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1644) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:164) at android.app.ActivityThread.main (ActivityThread.java:6494) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run (RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:807)
private File getTestFile(String filename) {
AssetManager assetManager = getAssets();
Log.d("nome do arquivo",filename);
InputStream in;
OutputStream out;
try {
in = assetManager.open(filename);
File cloneFile = new File("/data/data/" + getPackageName() + "/" + filename);
if (cloneFile.exists()) {
Log.d("teste",cloneFile.getName());
return cloneFile;
}
out = new FileOutputStream(cloneFile);
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
in.close();
out.flush();
out.close();
return cloneFile;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
He can change the image but can not find the file
private void setTextViews(int sdk, String uriPath,String realPath){
imageFile = new File(realPath);
Uri uriFromPath = Uri.fromFile(imageFile);
// you have two ways to display selected image
// ( 1 ) imageView.setImageURI(uriFromPath);
// ( 2 ) imageView.setImageBitmap(bitmap);
Bitmap bitmap = null;
File fileaux = imageFile.getAbsoluteFile();
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uriFromPath));
if(fileaux.exists()) {
String result = new ProcessSingleImageTask().execute(getTestFile(fileaux.getName())).get();
}else{
Log.d("a","arquivo não existe");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
imagemResolucao.setImageBitmap(bitmap);
Log.d("HMKCODE", "Build.VERSION.SDK_INT:"+sdk);
Log.d("HMKCODE", "URI Path:"+uriPath);
Log.d("HMKCODE", "Real Path: "+realPath);
}