简体   繁体   English

如何在我的手机/模拟器中打开 PDF 查看器(adobe pdf)

[英]How to open PDF viewer(adobe pdf) which in my mobile / emulator

When i click the file which i retrieve from database it will simply downloading.当我单击从数据库中检索的文件时,它只会下载。 i want to open it from my PDF viewer which in my Mobile我想从我的手机中的 PDF 查看器中打开它

I don't know how and where should i want to change or replace the code我不知道我应该如何以及在哪里更改或替换代码

This is the List View这是列表视图

A list view列表视图

This is the code which i use to develop这是我用来开发的代码

public class ViewFiles extends AppCompatActivity {

    //Variables
    ListView myViewFiles;
    DatabaseReference databaseReference;
    List<String> detail;
    List<uploadFiles> uploadDOCS;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_files);

        //Displaying the toolbar
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        //Assigning all the Variables to ID
        myViewFiles = (ListView) findViewById(R.id.myViewFiles);
        uploadDOCS = new ArrayList<uploadFiles>();

        detail =  new ArrayList<>();

        viewAllFiles();

        //On click option for the list view and open it from pdf
        myViewFiles.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                uploadFiles uploadFiles = uploadDOCS.get(position);

                //Intent intent = new Intent(ViewFiles.this, ViewPdfFiles.class);
                Intent intent = new Intent();
                intent.setType(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(uploadFiles.getUrl()));
                startActivity(intent);
            }
        });
    }

    //View files which in databse
    private void viewAllFiles() {

        databaseReference = FirebaseDatabase.getInstance().getReference("HNDIT").child("1st Year 2nd Sem").child("OOP");
        databaseReference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

                for (DataSnapshot postSnapshot: dataSnapshot.getChildren()){

                    uploadFiles uploadFiles = postSnapshot.getValue(com.example.lms.fileupload.uploadFiles.class);
                    uploadDOCS.add(uploadFiles);
                }

                String[] uploads = new String[uploadDOCS.size()];

                for (int i=0; i < uploads.length; i++){
                    uploads[i] = uploadDOCS.get(i).getName();

                }
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,uploads){
                    @NonNull
                    @Override
                    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
                        View view = super.getView(position, convertView, parent);
                        TextView myText = (TextView) view.findViewById(android.R.id.text1);
                        myText.setTextColor(Color.BLACK);

                        return view;
                    }
                };
                myViewFiles.setAdapter(adapter);
            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }
        });

    }
}

how can i fix this我怎样才能解决这个问题

Is there anyway to open inside the app无论如何要在应用程序内打开

Please see this too 这个也请看

https://github.com/barteksc/AndroidPdfViewer Use this library. https://github.com/barteksc/AndroidPdfViewer使用这个库。 This is best way to load PDF into Application's screen.这是将 PDF 加载到应用程序屏幕的最佳方式。

When I click the file which I retrieve from database it will simply start downloading.当我单击从数据库中检索的文件时,它将开始下载。

Intent.ACTION_VIEW will try to display the pdf file. Intent.ACTION_VIEW将尝试显示pdf 文件。 It requests the system to look for some Activity that is able to open and view this file.它要求系统寻找一些能够打开和查看这个文件的Activity That's why it will start downloading.这就是为什么它将开始下载。 This should be done only if you do not have special Activity in your own app that is capable of opening the file.仅当您自己的应用程序中没有能够打开文件的特殊Activity时,才应执行此操作。
Since, in this case, fortunately you do have your own capable Activity so, you should rather launch that Activity with uri of the pdf file as:因为,在这种情况下,幸运的是您确实有自己的能力Activity ,所以您应该使用 pdf 文件的uri启动该Activity

Intent intent = new Intent(ViewFiles.this, ViewPdfFiles.class);
//intent.setType(Intent.ACTION_VIEW);
intent.putExtra("url", uploadFiles.getUrl());
startActivity(intent);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM