3

Suppose I have an app named A with this data directory: com.example.test Now I want to make another app named B to modify something in com.example.test.

Of course I know both have to share the same signature. But what else do I have to have?

Basically I am trying to design an app to which users can plug in new components. Any idea?

Joseph_Marzbani
  • 1,796
  • 4
  • 22
  • 36

3 Answers3

3

I believe the safest approach would be to use a Content Provider. Then to access a file in application A from application B, you can declare a ContentProvider in application A and override the public ParcelFileDescriptor openFile(Uri uri, String mode) method. Then application B can access a file located in data directory of application A through an appropriate uri using the getContentResolver().openInputStream(...) method. For more information see:

http://www.grokkingandroid.com/handling-binary-data-with-contentproviders/

https://stackoverflow.com/a/4336013/1482726

Community
  • 1
  • 1
AggelosK
  • 4,313
  • 2
  • 32
  • 37
0

Both apps have to specify the same user ID in the manifest:

android:sharedUserId

The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process.

Disclaimer: I have never done this myself, but according to the documentation it should work.

Community
  • 1
  • 1
Henry
  • 42,982
  • 7
  • 68
  • 84
  • I had used sharedUserId for an application i was working with. When i used the same Android Project Library to be referenced in every Application i was getting some invalid ClassCastExceptions. I have posted [a question](http://stackoverflow.com/questions/11224064/running-multiple-applications-on-a-shared-process-with-a-shared-project-library) for a workaround. Till now i have not found any workaround other than avoiding using the same user id. – AggelosK Nov 26 '13 at 12:29
0

you can get a context of the other app by using Context.createPackageContent() and use CONTEXT_RESTRICTED, then you can use openFileOutput with only the file name. add this in AndroidManifest.xml :- by using protectionLevel="signature", only apps signed by you can access your content provider, and thus your files. and in both the app's AndroidManifest.xml ,write this :-