I have two apps from which i want to share data between the apps using content provider.What i do, i have create Content Provider in app A. Below is Manifest.xml file of app A.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kil.demoexample">
<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="com.kil.demoexample.ContentProvider.StudentsProvider.READ_DATABASE" android:protectionLevel="normal"/>
<permission android:name="com.kil.demoexample.ContentProvider.StudentsProvider.WRITE_DATABASE" android:protectionLevel="normal"/>
<application
android:debuggable="true"
android:name=".myApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="HardcodedDebugMode">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Login.LoginActivity"/>
<activity android:name=".Login.ObjectPassActivity"/>
<activity android:name=".Login.SignUpActivity"/>
<provider
android:name="com.kil.demoexample.ContentProvider.StudentsProvider"
android:authorities="com.kil.demoexample.ContentProvider.StudentsProvider"
android:exported="true"
android:readPermission="com.kil.demoexample.ContentProvider.StudentsProvider.READ_DATABASE"
android:writePermission="com.kil.demoexample.ContentProvider.StudentsProvider.WRITE_DATABASE"/>
</application>
</manifest>
Now in App B I am trying to access content provider on App A. Below in Manifest.xml file of app B.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kil.practicepro">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.kil.demoexample.ContentProvider.StudentsProvider.WRITE_DATABASE"/>
<uses-permission android:name="com.kil.demoexample.ContentProvider.StudentsProvider.READ_DATABASE"/>
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Activity.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
</application>
</manifest>
Now from app B i am trying below code to get data from app A content provider
ContentResolver cr=getContentResolver();
String URL = "content://com.kil.demoexample.ContentProvider.StudentsProvider/students";
Uri uri = Uri.parse(URL);
Cursor c=cr.query(uri,null,null,null,null);
if (c != null) {
if (c.moveToFirst()) {
do {
Log.d("column1",c.getString(0));
} while (c.moveToNext());
c.close();
}
}else{
Toast.makeText(this, "CursorIsNull", Toast.LENGTH_SHORT).show();
}
When iam trying to get data within app A it works fine but When i am trying to access content provider from app B it through me an error. I have check almost all the post on Stackoverflow. According to all the post i have set my permission in both AndroidManifest.xml but it still giving me an error of **java.lang.SecurityException: Permission Denial: opening provider ** is there is any mistake in my files please help me out from it.