Уже много дней мы сталкиваемся с этой проблемой. Способен к изображению, кстати. Всегда показывает «Ошибка загрузки». Мое приложение подключено к базе данных и хранилищу Firebase. Все остальные значения приложения успешно добавляются в базу данных. Но в Firebase Storage ничего не идет. Пожалуйста помоги. Моя загрузка:
public class UploadActivity extends AppCompatActivity {
StorageTask uploadTask;
Uri path;
StorageReference photoStorage;
DatabaseReference photoRef;
ImageView passportsize_photo;
Button upload_photo, chose_photo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
chose_photo =findViewById(R.id.choose_photo);
passportsize_photo =findViewById(R.id.passportsize_photo);
upload_photo =findViewById(R.id.upload_photo);
photoStorage = FirebaseStorage.getInstance().getReference("Photos");
photoRef = FirebaseDatabase.getInstance().getReference("Photos");
upload_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(uploadTask!=null&&uploadTask.isInProgress()){
Toast.makeText(UploadActivity.this, "Upload in progress", Toast.LENGTH_SHORT).show();
}else { uploadFile();}
}
});
chose_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openFileChooser();
}
});
}
private String getFileExtension(Uri uri) {
ContentResolver cR = this.getContentResolver();
MimeTypeMap mime = MimeTypeMap.getSingleton();
return mime.getExtensionFromMimeType(cR.getType(uri));
}
private void uploadFile() {
StorageReference Ref = photoStorage.child(System.currentTimeMillis() + "." + getFileExtension(path));
uploadTask = Ref.putFile(path)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
//Uri downloadUrl = taskSnapshot.getDownloadUrl();
Toast.makeText(UploadActivity.this, "Image Uploaded", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
// ...
Toast.makeText(UploadActivity.this, "Upload failed", Toast.LENGTH_SHORT).show();
}
});
}
private void openFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK
&& data != null && data.getData() != null) {
path = data.getData();
passportsize_photo.setImageURI(path);
//Picasso.get().load(path).into(passportsize_photo);
}
}
}
Мои зависимости:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.navigation:navigation-fragment:2.2.1'
implementation 'androidx.navigation:navigation-ui:2.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
//noinspection GradleCompatible,GradleCompatible
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation "androidx.cardview:cardview:1.0.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
implementation 'com.google.android.material:material:1.1.0-alpha10'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//firebase
implementation 'com.firebase:firebase-client-android:2.5.2'
implementation 'com.google.firebase:firebase-database:19.2.1'
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.firebase:firebase-analytics:17.3.0'
implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.4'
implementation 'com.google.firebase:firebase-messaging:20.1.5'
implementation 'com.firebaseui:firebase-ui-database:4.3.2'
//
//google sign in
implementation 'com.google.android.gms:play-services-auth:17.0.0'
//glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
//circular image
implementation 'de.hdodenhof:circleimageview:3.0.0'
//picasso
implementation 'com.squareup.picasso:picasso:2.71828'
}
Манифест:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Прочитал много форумов и статей, не нашел решения. Заранее спасибо.