CardView点击下载PDF

时间:2018-07-02 19:15:53

标签: java android

当我单击名片视图时,我想下载一个pdf文件,这就是我在视图支架中声明它的方式。

         holder.pdfLocation.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(final View v) {

                    final DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);

                    baptistDatabase.child(post_key).child("pdflocation").addListenerForSingleValueEvent(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {

                            String baptistpdf = dataSnapshot.getValue(String.class);

                            Uri uri = Uri.parse(baptistpdf);
                            DownloadManager.Request request = new DownloadManager.Request(uri);
                            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                            Long reference = dm.enqueue(request);
  }

这是我的LogCat

   FATAL EXCEPTION: main
Process: com.packageone.winter.tkpchanmariunitaizawl, PID: 13072
java.lang.NullPointerException: uriString
    at android.net.Uri$StringUri.<init>(Uri.java:475)
    at android.net.Uri$StringUri.<init>(Uri.java:465)
    at android.net.Uri.parse(Uri.java:437)
    at com.packageone.winter.tkpchanmariunitaizawl.BaptistS_pdf.BaptistPdfFiles$1$2$1.onDataChange(BaptistPdfFiles.java:108)

我的数据库就是这样。

 Baptists -> Pdf Files -> push() -> (key)pdflocation - "Storage Location Link"

当我单击“卡片”视图时,我想要的是我只想下载Pdf,因为我无法引用一个链接,因为当上传新的pdf文件时,它会不断变化。.

帮助...

0 个答案:

没有答案