If I create a ContentProvider and want it to be available to certain 3rd party apps but not too others.
How would one go about that?
Use permissions. Read about them here:
https://developer.android.com/guide/topics/providers/content-provider-creating.html#Permissions
Then you just need to publish those permissions to only those parties you wish to allow access.
You can add permission to provider. like
<provider
android:name="com.example.app.provider.MyProvider"
android:authorities="com.example.myprovider"
android:label="#string/app_name"
android:readPermission="com.example.permission.READ_PROVIDER" />
and write your own permission into manifest
<permission
android:name="com.example.permission.READ_PROVIDER"
android:description="provider_desc"
android:label="#string/permission_access_label"
android:protectionLevel="signature" />
Write this permission to manifest of the application which want to access provider.
Where signature insures that applications (which access provider and original are signed with same certificate)
Read more about Writing your own Content Provider
Related
We reviewed your request and found that your app, does not qualify for use of the requested permissions for the following reasons:
The declared feature {Default SMS} is allowed; however we determined it to be unnecessary for the core functionality of your app.
Default SMS [READ_SMS, SEND_SMS, WRITE_SMS, RECEIVE_SMS, RECEIVE_WAP_PUSH, RECEIVE_MMS]
I use the <uses-permission android:name="android.permission.SEND_SMS" />
to share the app via SMS (send a text and a link to the website ), whats the work arround?
Thanks
If I understand correctly you want SMS as a feature but not a requirement.
I think what you wanted to do is add uses-feature declarations with android:required="false".
From android docs
When you declare android:required="false" for a feature, it means that the application prefers to use the feature if present on the device, but that it is designed to function without the specified feature, if necessary.
Solved by removing <uses-permission android:name="android.permission.SEND_SMS" />
and calling a intent to open the Native Device Sms App
Is is possible to make content provider read-only? I know that this question was asked few times but according to all of them (eg. this) I have to write my own custom write permission.
<permission android:name="com.test.WRITE_DATABASE" android:protectionLevel="normal" />
<permission android:name="com.test.READ_DATABASE" android:protectionLevel="normal" />
//...
<provider
android:authorities="xxx"
android:name="xxx"
android:exported="true"
android:readPermission="com.test.READ_DATABASE"
android:writePermission="com.test.WRITE_DATABASE" />
But hacker could decompile my app and look inside manifest file and then he can easily write his own app with:
<uses-permission android:name="com.test.WRITE_DATABASE" />
So it's almost useless...
I have several apps to use one Content Provider inside my main application. Only this application should have write permission - other should only read from this database. Any ideas how to solve this?
See documentation about permissions here: https://developer.android.com/guide/topics/manifest/permission-element.html
Answer to your question is a android:protectionLevel property of a permission. You can set it to signature so only applications that signed with same key will be able to request this permissions.
I was trying to create a content provider serving to all Apps in system; kept getting security permission error when ran other Apps to read.
Could anyone help to show me the sample of how to compose read permission in Manifest, because I cannot access developer.android.com even by VPN in PRC...shame...thanks a lot...
To quote the developer docs:
Content Provider Permissions
A provider's application can specify permissions that other applications must have in order to access the provider's data. These permissions ensure that the user knows what data an application will try to access. Based on the provider's requirements, other applications request the permissions they need in order to access the provider. End users see the requested permissions when they install the application.
If a provider's application doesn't specify any permissions, then other applications have no access to the provider's data. However, components in the provider's application always have full read and write access, regardless of the specified permissions.
So you would need to declare a permission for the content provider in your manifest, such as:
<permission android:name="com.your.app.permission.READ_MY_PROVIDER"
android:label="#string/read_permission"
android:description="#string/read_permission_description"
android:protectionLevel="normal" />
As a child of the <application> element. The protection level should be normal if you want all apps to be able to access it, or signature if it should only be accessible by apps you have signed with the same key.
And add that permission to the provider like so:
<provider
...
android:readPermission="com.your.app.permission.READ_MY_PROVIDER"
... />
Then, request the same permission in the other apps, and they will be able to access your content provider:
<uses-permission android:name="com.your.app.permission.READ_MY_PROVIDER">
is there any way to make an external content provider available to only one package?
for example available only to my app?
Thanks in advance.
Although its too late, I would like to share the answer which I have found,
You need to declare your own custom permission inside manifest file of content provider application like this..
<permission android:name= "com.android.testpermission" android:protectionLevel="signature" >
And inside your Content Provider tag you have to specify a permission that a client is required to have like this way...
<provider android:name=".MyProvider"
android:authorities="com.example.contentproviderexample.MyProvider" android:exported="true" android:permission="com.android.testpermission" android:multiprocess="true" ></provider>
And inside your 2nd application to access content provider data you need to specify the uses permission inside manifest file,like this..
<uses-permission android:name="com.android.testpermission"/>
Now sign both the application using same keystore signature & this way any other application can't access your content provider data. Only applications that hold those permissions & signed with same keystore signature will be able to access the provider data.
You can add permissions to the manifest declaration for the content provider. Only applications that hold those permissions will be able to access the provider.
I noticed that there are two types of permissions in the manifest file, "permission" and "uses-permission" like the two shown below;
<permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
for the following 4 permissions which do I use when I put them in my manifest.xml file? uses-permissions or permissions?
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
android.permission.INTERNET
android.permission.CHANGE_WIFI_MULTICAST_STATE
For
<permission>
The documentation states:
Declares a security permission that can be used to limit access to specific components or features of this or other applications.
Therefore, since you are accessing Android's permissions, you want uses-permission instead. The documentation for this element states:
Requests a permission that the application must be granted in order
for it to operate correctly.
<permission> is normally used when making a custom permission (e.g. when making an app that other apps can tie in to, limiting access is a must), and <uses-permission> is used when your app actually needs a permission it doesn't have normally.
Lets start with "uses-permission...": Suppose you want to use GoogleMap in your application as an example to find a nearest location of any office such as bank or any other office. You need internet. So you need to give the permission to your android device to access INTERNET. This is done by using android permission called .
<uses-permission android:name="android.permission.INTERNET" />
Now come to "permission..": what it does is it Declares a security permission that can be used to limit access to specific components or features of this or other applications.If your application need some resources or some feature from other application, you can use by giving the specific class or package.
<permission android:name="com.example.project.DEBIT_ACCT" . . . />
Thanks. for more information, you can read
http://developer.android.com/guide/topics/manifest/manifest-intro.html
In short, the one you needed is the uses-permission statement.
Androird Document now has a dedicated page discussing these two usages.
In the Using Permissions part, it explains that
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.app.myapp" >
<uses-permission android:name="android.permission.RECEIVE_SMS" />
...
</manifest>
is used to declare what permissions you'd like to use.
While in Defining and Enforcing Permissions you can see that
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.me.app.myapp" >
<permission android:name="com.me.app.myapp.permission.DEADLY_ACTIVITY"
android:label="#string/permlab_deadlyActivity"
android:description="#string/permdesc_deadlyActivity"
android:permissionGroup="android.permission-group.COST_MONEY"
android:protectionLevel="dangerous" />
...
</manifest>
is used to define your own permission.
In layman terms, <uses-permission> specifies permissions your app needs to access some component restrict by another app that is the owner of that component.
<permission> specifies the restrictions you are placing on your components are the component owner.