0
votes

I have a pdf file which can be edited through Adobe Acrobat. When I open the file straight away from Adobe Acrobat app and edit the file, and when I press the back button it gets saved automatically, but when I open with Cordova application, it is opening with Adobe Acrobat app and I can also able to edit that, but when press the back button and come back to app and once again hit that particular pdf file from the Cordova application, it is not showing the edited content (it happens only with above android 7 versions, but below android version 7 it is working fine from the app).

I open the file with this code from Cordova,

var customPlugin = {
    createEvent : function(success, failure, action,arg1) {
        cordova.exec(success, // success callback function
        failure, // error callback function
        'Utils', // mapped to our native Java class
        action, // with this action name
        [arg1]);
    }
}

Here 'Utils' referred as my Java class in which I have written the function called openFile which mentioned below,

// open the file
private boolean openFile(String fileName, String contentType)
        throws JSONException {
File file = new File(fileName);

if (file.exists()) {
    try {
        Uri path = Uri.fromFile(file);
        PackageManager packageManager = this.cordova.getActivity()
                .getPackageManager();
        String application_id = "com.processdrive.novema";
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(
                    this.cordova.getActivity().getPackageName(), 0);
            application_id  = packageInfo.packageName;
        } catch (NameNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        if (Build.VERSION.SDK_INT >= 24) {             
            path = FileProvider.getUriForFile(this.cordova.getActivity(),
                application_id + ".provider",
                file);
        }
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        intent.setDataAndType(path, contentType);
        cordova.getActivity().startActivity(intent);
        return true;
    } catch (android.content.ActivityNotFoundException e) {
        return false;
    }
} else {
    return false;
}

}

The above code works as expected with below android 7 versions, but above android version 7 it is not working with the edited content in the PDF file.

Does it need any extra permission from the application or any other way? Thanks in advance!

1

1 Answers

0
votes

After so many hits, I got it fixed over here,

This works as expected

https://github.com/Evolution-36/cordova-plugin-file-opener2