Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have this in one of my applications which allows me access to local storage (user preference selectable before you have a go at me ;) )</p> <pre><code>import java.io.*; import android.content.*; import android.database.*; import android.net.*; import android.os.*; import android.preference.PreferenceManager; import android.util.Log; public class LocalFileContentProvider extends ContentProvider { private static final String URI_PREFIX = "content://your.content.provider.as.per.manifest"; public static String constructUri(String url) { Uri uri = Uri.parse(url); return uri.isAbsolute() ? url : URI_PREFIX + url; } @Override public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean allowLocal = app_preferences.getBoolean("allowLocalFiles", false); if (allowLocal) { try { File file = new File(uri.getPath()); if (file.isDirectory()) return null; ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY); return parcel; } catch (Exception e) { return null; } } else { return null; } } @Override public boolean onCreate() { return true; } @Override public int delete(Uri uri, String s, String[] as) { throw new UnsupportedOperationException("Not supported by this provider"); } @Override public String getType(Uri uri) { throw new UnsupportedOperationException("Not supported by this provider"); } @Override public Uri insert(Uri uri, ContentValues contentvalues) { throw new UnsupportedOperationException("Not supported by this provider"); } @Override public Cursor query(Uri uri, String[] as, String s, String[] as1, String s1) { throw new UnsupportedOperationException("Not supported by this provider"); } @Override public int update(Uri uri, ContentValues contentvalues, String s, String[] as) { throw new UnsupportedOperationException("Not supported by this provider"); } } </code></pre> <p>My manifest contains</p> <pre><code>&lt;provider android:name="it.automated.android.kiosk.se.LocalFileContentProvider" android:authorities="it.automated" /&gt; </code></pre> <p>and then to start the install (or action)</p> <pre><code>Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.setDataAndType(Uri.parse(url), mimeType); </code></pre>
 

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