Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

pdf intent does not have permission to launch

File file= new File(url);
file.setReadable(true, false);

Intent intent = new Intent(Intent.ACTION_VIEW);
Uri pdfUri = FileProvider.getUriForFile(getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", file);
intent.setDataAndType(pdfUri, "application/pdf");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

List<ResolveInfo> resInfoList = getApplicationContext().getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resInfoList) {
        String packageName = resolveInfo.activityInfo.packageName;
        getApplicationContext().grantUriPermission(packageName, pdfUri,
                Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }

Intent in = Intent.createChooser(intent, "Open File");
startActivity(in);
Comment

PREVIOUS NEXT
Code Example
Java :: rename action bar android 
Java :: 2d array length in java 
Java :: string to char 
Java :: how to convert integer to string in java 
Java :: how to create Java ArrayList 
Java :: Task :run FAILED Error: Could not find or load main class Caused by: java.lang.ClassNotFoundException: 
Java :: read excel file in java and store into arraylist 
Java :: java stream sort Collator 
Java :: declare id in java 
Java :: selenium drag slider 
Java :: check if LinkedList is empyth java 
Java :: Unexpected end of file in android studio activity main.xml 
Java :: how to translate java swing 
Java :: java run class file 
Java :: java inner method 
Java :: java string stringbuilder array list tostring 
Java :: java basic program 
Java :: inheritance in java 
Java :: android studio json parser 
Java :: java enum to string 
Java :: how to insert a 0 in an array java 
Java :: how to reverse numbers in java 
Java :: djava days between two dates 
Java :: how to change datatypes in java 
Java :: what is java 
Java :: change element in array java 
Java :: control structures in java 
Java :: binary to string java 
Java :: set up a tree in java 
Java :: loops in java 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =