Exact Difference between “Content-Provider” and “SQLite Database”

I found one major difference, as follows: Storing your data in a database is one good way to persist your data, but there’s a caveat in Android-databases created in Android are visible only to the application that created them. That is to say, a SQLite database created on Android by one application is usable only … Read more

Best practices for exposing multiple tables using content providers in Android

It’s probably a bit late for you, but others may find this useful. First you need to create multiple CONTENT_URIs public static final Uri CONTENT_URI1 = Uri.parse(“content://”+ PROVIDER_NAME + “/sampleuri1”); public static final Uri CONTENT_URI2 = Uri.parse(“content://”+ PROVIDER_NAME + “/sampleuri2”); Then you expand your URI Matcher private static final UriMatcher uriMatcher; static { uriMatcher = … Read more

CursorLoader usage without ContentProvider

I wrote a simple CursorLoader that does not need a content provider: import android.content.Context; import android.database.Cursor; import android.support.v4.content.AsyncTaskLoader; /** * Used to write apps that run on platforms prior to Android 3.0. When running * on Android 3.0 or above, this implementation is still used; it does not try * to switch to the framework’s … Read more

Why does ContentResolver.requestSync not trigger a sync?

Calling requestSync() will only work on an {Account, ContentAuthority} pair that is known to the system. Your app needs to go through a number of steps to tell Android that you are capable of synchronizing a specific kind of content using a specific kind of account. It does this in the AndroidManifest. 1. Notify Android … Read more

How to use support FileProvider for sharing content to other apps?

Using FileProvider from support library you have to manually grant and revoke permissions(at runtime) for other apps to read specific Uri. Use Context.grantUriPermission and Context.revokeUriPermission methods. For example: //grant permision for app with package “packegeName”, eg. before starting other app via intent context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); //revoke permisions context.revokeUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); As a … Read more

tech