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

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

sharedUserID is declared in the AndroidManifest file, so database is created after setting the sharedUserId.
did you successfully connect to database in second application (did u try insert or select rows?)
Yes, I can get data in the second application
hm.. Could you share somehow your project? I would really appreciate it.
Sorry for the late response. Please try this
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.