Skip to content Skip to sidebar Skip to footer

Pdf Files As Part Of Android .apk

I have to build an Android application which shows a list of pdf files. These pdf files should be secured, in other words - the user of the app should not be able to get a copy of

Solution 1:

Probably you should store it in the res/raw folder

Solution 2:

You can copy this(these) pdf file(s) into assets folder, thus your files will be the part of your application and can not be accessible outside, and you can also treat them as normal files (i.e. open with any pdf viewer in your case). Whenever you want to get access to context file you can call context.getAssets() .

Hope this information helps.

Update : Here is the code I am using to open a file in downloads directory, this code can open the pdf file in any compatible pdf reader if installed on phone, Tested with Adobe Reader. You will need a URI of the pdf file in assets folder to run the code.

StringfileName= pdfUrl.substring(pdfUrl.lastIndexOf("/"));

        Log.i("fileName", "" + fileName);
        Filefile=newFile("/sdcard/download" + fileName);
        // File file = new// File("/sdcard/download/airtel_latest000.mp3");

        Intent intent;
        if (file.exists()) {

            Uripath= Uri.fromFile(file);

            intent = newIntent(Intent.ACTION_VIEW);

            intent.setDataAndType(path, "application/pdf");

            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            downloaded = true;

        } else {

            intent = newIntent(Intent.ACTION_VIEW);

            intent.setData(Uri.parse(pdfUrl));

            downloaded = false;
        }
        try {
            startActivityForResult(intent, 5);

        } catch (ActivityNotFoundException e) {
            Toast.makeText(this, "No Application Available to View PDF",
                    Toast.LENGTH_SHORT).show();
        }

Post a Comment for "Pdf Files As Part Of Android .apk"