Estoy intentando hacer una pequeña apk para hacer un respaldo de las imágenes y subirlas a firebase. A ver si alguien me puede ayudar. Al poner el boleano para que compruebe si ya está subida la imagen para pasar a la siguiente no llega al if para que lo ponga a true entonces solo me sube una imagen. No se como hacerlo para que espere a que el progreso sea del 100% y la imagen este subida para que cambie el boleano y pase a la siguiente. Si lo intento hacer de golpe la apk crashea.
Caused by: java.util.concurrent.RejectedExecutionException: Task com.google.firebase.storage.zzr@68a150 rejected from java.util.concurrent.ThreadPoolExecutor@1933f49[Running, pool size = 2, active threads = 2, queued tasks = 128, completed tasks = 0]
private StorageReference mStorageRef;
private static final String CAMERA = "/storage/emulated/0/DCIM/Camera";
private boolean isDownloaded = true;
private TextView status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mStorageRef = FirebaseStorage.getInstance().getReference();
status = findViewById(R.id.count);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
uploadFile(CAMERA);
}
});
}
private void uploadFile(String path) {
File directorio = new File(path);
final File[] arrayFiles = directorio.listFiles();
if (arrayFiles != null) {
for (int i = 0; i < arrayFiles.length; i++) { //arrayFiles.length
if (isDownloaded) {
isDownloaded = false;
Log.d("BOLEANO VUELTAS:", isDownloaded + " " + i);
Log.d("FILE " + i, arrayFiles[i].getAbsolutePath());
final int copia = i;
Uri uri = Uri.fromFile(arrayFiles[i]);
StorageReference filepath = mStorageRef.child("Fotos").child(uri.getLastPathSegment());
filepath.putFile(uri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
Uri downloadUrl = taskSnapshot.getDownloadUrl();
Log.d("SUBIDO", arrayFiles[copia].getName());
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
// ...
Log.d("ERROR", exception.toString());
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
long progress = taskSnapshot.getBytesTransferred();
long total = taskSnapshot.getTotalByteCount();
status.setText("EN PROGRESO: " + arrayFiles[copia].getName() + " " + +taskSnapshot.getBytesTransferred());
Log.d("EN PROGRESO", arrayFiles[copia].getName() + " " + +taskSnapshot.getBytesTransferred());
if (total == progress) {
isDownloaded = true;
status.setText("SUBIDO:" + arrayFiles[copia].getName());
}
}
});
}
}
} else {
Log.d("VACIA", "NO HAY ARCHIVOS");
}
}
public String pathUltimaCarpeta(String path) {
String[] bits = path.split("/");
String lastWord = bits[bits.length - 1];
return lastWord;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}