Already run each part code:
Within the app file
Dependencies {
Implementation fileTree (dir: 'libs', include: [' *. Jar'])
Implementation 'androidx. Appcompat: appcompat: 1.0.2'
Implementation 'androidx. Constraintlayout: constraintlayout: 1.1.3'
TestImplementation 'junit: junit: 4.12'
AndroidTestImplementation 'androidx. Test. Ext: junit: 1.1.0'
AndroidTestImplementation 'androidx. Test. Espresso: espresso - core: 3.1.1'
Implementation files (' libs/waterlibrary - debug. Aar)
}
Androidmanifest.xml
& lt; The provider
The android: name="androidx. Core. Content. FileProvider"
Android: authorities="${applicationId}. Fileprovider"
Android: grantUriPermissions="true"
Android: exported="false" & gt;
<meta - data
The android: name="android. Support. FILE_PROVIDER_PATHS"
Android: resource="@ XML/file_paths"/& gt;
, of course, also add the permissions
& lt; USES - the permission of the android: name="android. Permission. WRITE_EXTERNAL_STORAGE"/& gt;
XML/file_paths code inside the& lt; ? The XML version="1.0" encoding="utf-8"?>
Start the installation codeFile mfile=new File (path);
Intent install=new Intent ();
Install. AddFlags (Intent. FLAG_ACTIVITY_NEW_TASK);
The setAction (Intent. ACTION_VIEW);
If (Build) VERSION) SDK_INT & gt;=Build. VERSION_CODES. N) {
//is the android version 7.0 and above
Uri apkUri=FileProvider. GetUriForFile (context, pageNameString + ". FileProvider ", mfile);
Install. AddFlags (Intent. FLAG_GRANT_READ_URI_PERMISSION);//without this sentence, "occurs on the installation parsing packet error prompt, actual Intent is do not have permission to read the file, then is the preliminary to the permissions (because it is not in the main thread execute)
The setDataAndType (apkUri, "application/VND. Android. Package - archive");
} else {
//is under the android 7.0 version//
Install. SetDataAndType (Uri) fromFile (mfile), "application/VND. Android. Package - archive");
}
The context. StartActivity (install);
The above has been to run code
In another app, I found that after contrast may be IDE the upgrade I didn't pay attention
Where
The code in this app
Dependencies {
Implementation fileTree (dir: 'libs', include: [' *. Jar'])
Implementation 'com. Android. Support. The constraint, the constraint - layout: 1.1.3'
Implementation 'com. Android. Support: design: 28.0.0'
Implementation 'com. Android. Support: support - annotations: 28.0.0'
Implementation 'android. Arch. Lifecycle: extensions: 1.1.1'
TestImplementation 'junit: junit: 4.12'
AndroidTestImplementation 'com. Android. Support. Test: runner: 1.0.2'
AndroidTestImplementation 'com. Android. Support. Test. Espresso: espresso - core: 3.0.2'
Implementation files (' libs/waterlibrary - debug. Aar)
}
The corresponding AndroidManifest. XML became so& lt; The provider
The android: name="android. Support. The v4. Content. FileProvider"
Android: authorities="${applicationId}. Fileprovider"
Android: grantUriPermissions="true"
Android: exported="false" & gt;
<meta - data
The android: name="android. Support. FILE_PROVIDER_PATHS"
Android: resource="@ XML/file_paths"/& gt;
Main is different here
The android: name="android. Support. The v4. Content. FileProvider"
Before the android: name="androidx. Core. Content. FileProvider"
Originally I want to quote packages are changed, but it doesn't work, without change the references in the app, in AndroidManifest reference, but the app cannot be launched,
So I was depressed, under the current reference, how do we start the apk installation!
Urgent, such as action genuflect is begged!CodePudding user response:
What is the error message?CodePudding user response: