0

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:

  1. SharedUserId is same for both apps
  2. 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;
};    
  1. 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:

  1. change PackageContextFlags.IgnoreSecurity to PackageContextFlags.IncludeCode .. But then sharedContext = null

  2. 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

Grzegorz G.
  • 1,285
  • 2
  • 14
  • 27

1 Answers1

1

I have tested your code, it works. Did you create the database before you set the sharedUserId? When I test this scenario, I meet this problem. If so, uninstall and reinstall the app could solve this problem.

Billy Liu - MSFT
  • 2,168
  • 1
  • 8
  • 15