6

maybe my question sounds like asked 100 times before, but believe me I have read every answer for those 100 similar questions and non of them solved my problem. So purpose of my native extension is to share documents in my app cache folder (doc, pdf, etc.) with third party apps (Quick Office, Adobe Reader etc). I found that FileProvider and Intents should solve my problem.

My app description file contains:

<application android:enabled="true"
                android:launchMode="singleInstance">
                <provider
                    android:name="android.support.v4.content.FileProvider"
                    android:authorities="com.test.fileprovider"
                    android:exported="false"
                    android:grantUriPermissions="true">
                    <meta-data
                        android:name="android.support.FILE_PROVIDER_PATHS"
                        android:resource="@xml/file_paths" />
                </provider>
            </application>

In Eclipse in Project properties -> Java Build Path -> Order and Export selected: Android Private libraries and Android Dependencies. android-support-v4.jar is inside project's libs folder.

FREFunction code excerpt:

package com.test.OpenWithDefaultApp.functions;

.....

import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.FileProvider;

.....

Uri contentUri = FileProvider.getUriForFile(context.getActivity(), "com.test.OpemWithDefaultApp.fileprovider", file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(contentUri, fileType);

.....

context.getActivity().startActivity(intent);

.....

I'm using

Eclipse Luna 4.4.0
Eclipse Android Plugin 23.0.3
Android SDK Tools 23.0.2
Android SDK Platform-tools 20
Android SDK Build-tools 20
Android SDK from 14 upto 20
Android Support Library 20
Google Play services 19

Native extension structure:

+android
      -libs/android-support-v4.jar
      -res/xml/file_paths
      -library.swf
      -openwithdefaultapp.jar
+default
      -library.swf
-extension.xml

But I'm stuck with error:

java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/air.testFileProvider-2.apk"],nativeLibraryDirectories=[/data/app-lib/air.testFileProvider-2, /vendor/lib, /system/lib]]

Any help would be appreciated. Thanks

MrClockOff
  • 103
  • 1
  • 2
  • 10
  • Have you seen http://stackoverflow.com/questions/9085189/how-to-add-third-party-jar-files-into-my-android-application-jar-file or https://forums.adobe.com/message/4806229? This sounds like the same root issue. – Brian Aug 13 '14 at 20:48
  • Thanks Brian! yozhik answer on http://stackoverflow.com/a/9118795/3938174 solved my problem. The only thing I don't like is the new size of my jar (700kb insted of 10kb) but at least it works! Thanks! – MrClockOff Aug 14 '14 at 09:16
  • This problem was happening to your because the generated `AndroidManifest.xml` was including tags for which your jar file had no dependencies (i.e.**android.support.v4.content.FileProvider**). – IgorGanapolsky Aug 09 '16 at 13:36
  • @IgorGanapolsky, how to fix this? – Hemang Apr 25 '17 at 05:31
  • @Hemang You need to find out which Google/Android apis you need in your project, and construct your **build.gradle** file accordingly. Or include the hard-coded jars in the **/lib** folder if you wish. – IgorGanapolsky Apr 25 '17 at 13:18
  • 1
    @IgorGanapolsky, Thanks Igor, lastly, I solved it by cleaning up my build folder and it compiled again. – Hemang Apr 26 '17 at 05:08

2 Answers2

0

android:authorities="com.test.fileprovider" and "com.test.OpemWithDefaultApp.fileprovider", both these names should be same

Rick
  • 1,177
  • 1
  • 19
  • 27
piyushpk
  • 91
  • 10
0

in AndroidManifest.xml

change

<provider android:name="android.support.v4.content.FileProvider"

to

<provider android:name="androidx.core.content.FileProvider"

tested and works for me