Skip to content

Commit

Permalink
Merge pull request #4 from lchforcom/master
Browse files Browse the repository at this point in the history
fix:remove outdated jar, and new FileProvide to avoid conflict
  • Loading branch information
cigalecigales authored Sep 27, 2020
2 parents b4d3efd + b07f76d commit 1881321
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
8 changes: 6 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@
<preference name="AndroidPersistentFileLocation" value="Internal" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<provider android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<provider
android:name="plugin.apkInstaller.ApkInstallerProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
</provider>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
</config-file>
<source-file src="src/android/ApkInstaller.java" target-dir="src/plugin/apkInstaller/"/>
<source-file src="src/android/ApkInstallerProvider.java" target-dir="src/plugin/apkInstaller/"/>
<source-file src="src/android/xml/file_paths.xml" target-dir="res/xml/"/>
<lib-file src="src/android/libs/android-support-v4.jar" />
</platform>
</plugin>
12 changes: 8 additions & 4 deletions src/android/ApkInstaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Context;
import android.support.v4.content.FileProvider;
import java.text.SimpleDateFormat;
import android.util.Log;

public class ApkInstaller extends CordovaPlugin {

Expand All @@ -20,11 +21,14 @@ public class ApkInstaller extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
if (action.equals(ACTION_INSTALL)) {
String fileName = data.getString(0);
Context context = this.cordova.getActivity().getApplicationContext();
File file = new File(context.getFilesDir() + "/" + fileName);

try {
String fileName = data.getString(0);
Context context = this.cordova.getActivity().getApplicationContext();
String filepath = context.getFilesDir() + "/" + fileName;
Log.d("apkInstaller", filepath);
File file = new File(context.getFilesDir() + "/" + fileName);


// Get file uri
Uri uri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file);
Intent intent = new Intent(Intent.ACTION_VIEW);
Expand Down
7 changes: 7 additions & 0 deletions src/android/ApkInstallerProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package plugin.apkInstaller;

import android.support.v4.content.FileProvider;

public class ApkInstallerProvider extends FileProvider {
// avoid android:authrities conflict with other lib which also use android.support.v4.content.FileProvider
}
Binary file removed src/android/libs/android-support-v4.jar
Binary file not shown.

0 comments on commit 1881321

Please sign in to comment.