PDF意向和错误的文件网址

时间:2019-02-15 14:44:54

标签: android firebase-realtime-database firebase-storage

当前,我正在制作一个将某些pdf文件上传到Firebase存储器的项目,以便我可以在recyclerView上检索该文件,但是当我单击recyclerView项时出现此错误:

02-15 14:35:56.510 18215-18215 / com.example.carlos.helpmschool E / Android运行时:致命异常:主要     流程:com.example.carlos.helpmschool,PID:18215     android.content.ActivityNotFoundException:未找到用于处理Intent {dat=com.google.android.gms.tasks.zzu@4ede29a}

的活动
public   class  ViewHolder extends RecyclerView.ViewHolder{

    TextView testsDescri,namePublish;


    public ViewHolder(View itemView) {
        super(itemView);
        testsDescri = itemView.findViewById(R.id.teste_description);
        namePublish = itemView.findViewById(R.id.name);

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = recyclerView.getChildLayoutPosition(v);
                Intent intent = new Intent();
                intent.setType(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(urls.get(position)));
                context.startActivity(intent);

            }
        });
    }
}

private void uploadFile(Uri pdfUri){

    progressBar.setVisibility(View.VISIBLE);

        final String name = System.currentTimeMillis() + ".pdf";
        final String name1 = System.currentTimeMillis()+"";
        final StorageReference storageReference = firebaseStorage.getReference();

        storageReference.child("Uploads").child(name).putFile(pdfUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                progressBar.setVisibility(View.GONE);
                String url = storageReference.getDownloadUrl().toString();
                DatabaseReference databaseReference = firebaseDatabase.getReference();


                databaseReference.child(name1).setValue(url).addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()){
                            intent();
                        }else {
                            Toast.makeText(DescriptionActivity.this, "ERROR", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {

                Toast.makeText(DescriptionActivity.this, "ERROR", Toast.LENGTH_SHORT).show();

            }
        }).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {

            }
        });

    }

我还认为我遇到了该错误,因为我获取的实时数据库URL的格式为“ com.google.android.gms.tasks.zzu@4ede29a”而不是“ https”格式。

0 个答案:

没有答案