我通过观看一系列教程来学习在Android中编程,在Android Studio中使用Firebase制作一个简单的博客应用。
在本教程的这一部分中,我完成了与使用ImageButton和EdiTexts上传到我的Firebase存储(带有标题和描述的图像)所提到的完全相同的内容,但是当我提交图像时,这会无限期地保持收费和吐司" 发布到博客...... "永远不会结束,图像也不会上传到我的数据库。
我检查过我已根据https://firebase.google.com/docs/中的步骤将我的Firebase的规则更改为公开,包括在数据库和存储中。
这里是8 min tutorial。
选择图片并写下标题和说明后,我点击提交按钮,然后控制台中出现此错误:
W/DynamiteModule: Failed to retrieve remote module version.
W/DynamiteModule: Failed to load module via fast routecom.google.android.gms.dynamite.DynamiteModule$zza: Failed to connect to dynamite module ContentResolver.
W/GooglePlayServicesUtil: Google Play services out of date. Requires 10084000 but found 9877470
W/DynamiteModule: Local module descriptor class for com.google.android.gms.firebasestorage not found.
I/DynamiteModule: Considering local module com.google.android.gms.firebasestorage:0 and remote module com.google.android.gms.firebasestorage:0
E/NetworkRqFactoryProxy: NetworkRequestFactoryProxy failed with a RemoteException:
com.google.android.gms.dynamite.DynamiteModule$zza: No acceptable module found. Local version is 0 and remote version is 0.
at com.google.android.gms.dynamite.DynamiteModule.zza(Unknown Source)
at com.google.android.gms.dynamite.DynamiteModule.zza(Unknown Source)
at com.google.android.gms.internal.zzbre.<init>(Unknown Source)
at com.google.android.gms.internal.zzbre.zzj(Unknown Source)
at com.google.firebase.storage.StorageReference.zzaaN(Unknown Source)
at com.google.firebase.storage.UploadTask.zzaba(Unknown Source)
at com.google.firebase.storage.UploadTask.run(Unknown Source)
at com.google.firebase.storage.StorageTask$8.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
E/UploadTask: Unable to create a network request from metadata
android.os.RemoteException
at com.google.android.gms.internal.zzbre.<init>(Unknown Source)
at com.google.android.gms.internal.zzbre.zzj(Unknown Source)
at com.google.firebase.storage.StorageReference.zzaaN(Unknown Source)
at com.google.firebase.storage.UploadTask.zzaba(Unknown Source)
at com.google.firebase.storage.UploadTask.run(Unknown Source)
at com.google.firebase.storage.StorageTask$8.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: null
android.os.RemoteException
at com.google.android.gms.internal.zzbre.<init>(Unknown Source)
at com.google.android.gms.internal.zzbre.zzj(Unknown Source)
at com.google.firebase.storage.StorageReference.zzaaN(Unknown Source)
at com.google.firebase.storage.UploadTask.zzaba(Unknown Source)
at com.google.firebase.storage.UploadTask.run(Unknown Source)
at com.google.firebase.storage.StorageTask$8.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: null
android.os.RemoteException
at com.google.android.gms.internal.zzbre.<init>(Unknown Source)
at com.google.android.gms.internal.zzbre.zzj(Unknown Source)
at com.google.firebase.storage.StorageReference.zzaaN(Unknown Source)
at com.google.firebase.storage.UploadTask.zzaba(Unknown Source)
at com.google.firebase.storage.UploadTask.run(Unknown Source)
at com.google.firebase.storage.StorageTask$8.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
E/EGL_emulation: tid 2710: eglSurfaceAttrib(1146): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x8b8cd120, error=EGL_BAD_MATCH
我的java类
public class PostActivity extends AppCompatActivity {
private ImageButton mSlectImage;
private EditText mPostTittle;
private EditText mPostDesc;
private Button SubmitButton;
private Uri mImageUri= null;
private static final int GALLERY_REQUEST=1;
private StorageReference mStorage;
private ProgressDialog mProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
mStorage= FirebaseStorage.getInstance().getReference();
mPostTittle=(EditText) findViewById(R.id.CreatePost_title);
mPostDesc=(EditText) findViewById(R.id.CreatePost_description);
SubmitButton=(Button) findViewById(R.id.Publicar_button);
mProgress=new ProgressDialog(this);
mSlectImage=(ImageButton) findViewById(R.id.imageButton);
mSlectImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent=new Intent(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent,GALLERY_REQUEST);
}
});
SubmitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startPosting();
}
});
}
private void startPosting() {
mProgress.setMessage("Posting to Blog...");
mProgress.show();
String title_val= mPostTittle.getText().toString().trim();
String desc_val= mPostDesc.getText().toString().trim();
if (!TextUtils.isEmpty(title_val)&& !TextUtils.isEmpty(desc_val)&& mImageUri!=null){
StorageReference filepath=mStorage.child("Blog_images").child(mImageUri.getLastPathSegment());
filepath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUri = taskSnapshot.getDownloadUrl();
mProgress.dismiss();
}
});
}
}
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
if (requestCode==GALLERY_REQUEST && resultCode==RESULT_OK){
mImageUri=data.getData();
mSlectImage.setImageURI(mImageUri);
}
}
}
布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_post"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.social.socialpart.socialpart.PostActivity">
<ImageButton
android:layout_marginTop="15dp"
android:layout_width="250dp"
android:layout_height="150dp"
android:id="@+id/imageButton"
android:background="@color/transparent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/post"
android:scaleType="centerCrop"
android:adjustViewBounds="true" />
<EditText
android:background="@color/colorPrimary"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="title"
android:ems="10"
android:layout_below="@+id/imageButton"
android:layout_centerHorizontal="true"
android:id="@+id/CreatePost_title" />
<EditText
android:background="@color/colorPrimary"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Description"
android:ems="10"
android:layout_below="@+id/CreatePost_title"
android:layout_centerHorizontal="true"
android:id="@+id/CreatePost_description" />
<Button
android:text="Submit post"
android:background="@color/colorPrimary"
android:textColor="@color/cardview_light_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Publicar_button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
感谢任何帮助。