The two apps have the same sharedUserId. When I use this code in app1
First of all, NEVER use a full path to internal storage like
/data/data. Let the operating system give you the path (for example, via
Environment.getExternalStorageState()). Don't make assumption on where the data is.
Secondly - you already are doing that! Unlike
Context.openFileOutput already prepends
/data/data/[package] to your path, so you don't need to specify that. Just specify the file name.
If you really feel that it's safe and necessary, and if both apps share the same user ID using android:sharedUserId in the manifest, you can get a context of the other app by using
Context.createPackageContext() and use CONTEXT_RESTRICTED, then use openFileOutput with only the file name.