Android resolveContentProvider returns null -
i want following in application. first need login. then, after log in quit application. running @ background. log in records still hold. need choose file file browser. after choosing file press share option. choose application operations on file. after make operations on file record cache. want open file on other appropriate application. can of them there problem while calling geturiforfile method.
string mimetype = getmimetype(fileuri);//returns mime type file imagepath = new file(context.getcachedir(), "/"); string fileuristr = fileuri.getlastpathsegment(); file newfile = new file(imagepath, fileuristr); try { newfile.createnewfile(); } catch (ioexception e) { e.printstacktrace(); } uri = fileprovider.geturiforfile(context, context.getpackagename(), newfile);
in manifest added fileprovider.
<activity android:name=".mainactivity" android:label="@string/app_name"> <provider android:name="android.support.v4.content.fileprovider" android:authorities="${applicationid}.share" android:exported="false" android:granturipermissions="true"> <meta-data android:name="android.support.file_provider_paths" android:resource="@xml/file_paths" /> </provider> <!--normal way opener --> <intent-filter android:label="appname"> <action android:name="android.intent.action.main" /> </intent-filter> <!--from share options opener --> <intent-filter> <action android:name="android.intent.action.send" /> <action android:name="android.intent.action.send_multiple" /> <category android:name="android.intent.category.default" /> <data android:mimetype="*/*" /> </intent-filter> </activity>
in file_paths.xml have following code:
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"> <cache-path name="cache_docs" path="data/data/com.app.firm.app/cache" /> </paths>
i opened fileprovider.java file. error from:
final providerinfo info = context.getpackagemanager() .resolvecontentprovider(authority, packagemanager.get_meta_data); final xmlresourceparser in = info.loadxmlmetadata( context.getpackagemanager(), meta_data_file_provider_paths); if (in == null) { throw new illegalargumentexception( "missing " + meta_data_file_provider_paths + " meta-data"); }
info parameter null. when program calls info.loadxmlmetadata gets null pointer exception. context.getpackagemanager
returns null. remember @ time have 2 applications running @ same time. 1 of follows natural flow (i.e -> login , main activity). other opens mainactivity. context.getpackagemanager
called second running application. please me
i know how solve problem , think can you.
maybe have 2 <provider>
, 1 of in lib, 1 of project
you can custom class extends fileprovider
, , change <provide>
name tag custom fileprovider
:
<provider android:name="xxxx.yourcustomfileprovider" android:authorities="${applicationid}.share" android:exported="false" android:granturipermissions="true"> <meta-data android:name="android.support.file_provider_paths" android:resource="@xml/file_paths" /> </provider>
and problem solved.
thanks!
Comments
Post a Comment