Note that there are some explanatory texts on larger screens.

plurals
  1. POCan a DocumentsProvider <provider> tag be used in an Android manifest targeting APIs < 19?
    text
    copied!<p>So I'm trying to implement the new Storage Access Framework stuff introduced in Android 4.4 (KitKat). I've extended a <a href="http://developer.android.com/reference/android/provider/DocumentsProvider.html" rel="nofollow noreferrer">DocumentsProvider</a> class as <a href="http://www.youtube.com/watch?v=zxHVeXbK1P4" rel="nofollow noreferrer">described on YouTube</a>, which works <a href="https://stackoverflow.com/questions/19834842/android-gallery-on-kitkat-returns-different-uri-for-intent-action-get-content/20209829#20209829">great</a> when I try it on KitKat (API 19) devices. I have a content provider, and my app acts as a client-- it's a great file picker to replace the one I had to custom-write.</p> <p>But when the code is run on older devices, such as API 8 (Froyo), it dies on launch with an error that looks like this: </p> <pre><code>E/AndroidRuntime( 702): FATAL EXCEPTION: main E/AndroidRuntime( 702): java.lang.RuntimeException: Unable to get provider com.example.MyProvider: java.lang.ClassNotFoundException: com.example.MyProvider in loader dalvik.system.PathClassLoader[/data/app/com.example-2.apk] </code></pre> <p>Makes perfect sense-- The <code>DocumentsProvider</code> class was introduced in KitKat, so of course it doesn't run in Froyo (API 8).</p> <p>To try to deal with older devices and make it fallback to the file picker I wrote previously, I wrapped all the code referencing <code>MyProvider</code> (my <code>DocumentsProvider</code>) with a <code>if ((Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT)</code> conditional... so you'd think I'd be safe...</p> <p>Trouble is, <code>DocumentsProvider</code> requires the provider be registered in <code>AndroidManifest.xml</code> within a <code>&lt;provider&gt;</code> element. I see no way of saying "Ignore this and don't try to load <code>MyProvider</code> on older APIs." And I don't see any way of declaring <code>&lt;provider&gt;</code> programmatically either. Or any kind of legacy solution. It seems to be an all-or-nothing thing hard-coded into the Manifest.</p> <p>If I remove the <code>&lt;provider&gt;</code> stuff from the manifest, the app runs perfectly in Froyo without errors (it's not trying to load or use <code>DocumentsProvider</code> at all). But I do need it there for KitKat to work with the new Storage Access stuff.</p> <p>Anyone have any thoughts? Is it possible to use <code>DocumentProvider</code> in a way that it works on API >= 19 but is completely ignored on older devices? Some kind of tricky wrapper-class... or a stub <code>ContentProvider</code> class... or <em>something</em>? Whatever class I can get Froyo to think is there, it'll never get called/used, at least by my app.</p> <p>Much thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload