I share my .db sqlite file between two aplications.
I succesful shared this file ( because second application can see it ) and just cant use it. I guess that is because of security reasons.
This is how I done sharing:
- SharedUserId is same for both apps
- simply creation of database
var Folder =
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
using (var conn = new SQLiteConnection(System.IO.Path.Combine(Folder, "Paczki.db")))
{
conn.CreateTable<Odczyt>();
return true;
};
- Receiving shared context.
Context sharedContext = null;
try
{
sharedContext =
this.CreatePackageContext(
"MobilnePaczki.MobilnePaczki", PackageContextFlags.IgnoreSecurity);
}
catch (Exception e)
{
}
using (var conn =
new SQLiteConnection(sharedContext.DataDir.ToString() + "/files/Paczki.db")) //I am sure that file exists
//... Could not open database file: ... files/Paczki.db (CannotOpen)
What I tried:
change
PackageContextFlags.IgnoreSecurity
toPackageContextFlags.IncludeCode
.. But thensharedContext = null
Copy .db file to second app and then connect to it, then I get an
UnauthorizedAccessException
From other threads like this and I can see that it is possible to use db file from other application.
Do you have any idea what can i do in such a problem?
UPDATE
Thanks to Billy's answer I found out that I declared my SharedUserId in <application>
tag in AnfroidManifest.xml
.
The correct way is to declare it in <manifest>
tag..
<manifest (...) android:sharedUserId="App.Id">
After I changed it I got INSTALL_FAILED_UID_CHANGED
Error when I was installing application. To fix this I used:
adb shell rm -rf /data/data/appname.appname