Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data sharing between two applications

Tags:

android

Recently i had an interview in which the question was asked as "How would you be able to share the data between two installed apps or apk's?"

I didn't have any answer for this question. Can anyone help me in determining an way to do so...

like image 668
Rahul Kalidindi Avatar asked Apr 21 '11 14:04

Rahul Kalidindi


People also ask

How do you share data between two applications?

Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.

Who manage data sharing between applications?

Answer - C) A content provider is used to share information between Android applications. 11.

Can an app access data from another app?

Just as an app can send data to other apps, it can also receive data from other apps as well. Think about how users interact with your application and what data types you want to receive from other applications.

What is a data sharing app?

It allows the transfer of the data between any two Android devices (Lenovo, HTC, Motorola, etc.). The app can also transfer data between two Android devices through the SD card even. You can transfer contacts, calendars, pictures, music, text messages, and much more.


2 Answers

Send data from Application 1 (for ex:Application 1 package name is "com.sharedpref1" ).

SharedPreferences prefs = getSharedPreferences("demopref",                     Context.MODE_PRIVATE);             SharedPreferences.Editor editor = prefs.edit();             editor.putString("demostring", strShareValue);             editor.commit(); 

Receive the data in Application 2( to get data from Shared Preferences in Application 1).

    try {             con = createPackageContext("com.sharedpref1", 0);//first app package name is "com.sharedpref1"             SharedPreferences pref = con.getSharedPreferences(                         "demopref", Context.MODE_PRIVATE);             String your_data = pref.getString("demostring", "No Value");         }      catch (NameNotFoundException e) {                 Log.e("Not data shared", e.toString());          } 

In both application manifest files add same shared user id & label,

 android:sharedUserId="any string"   android:sharedUserLabel="@string/any_string" 

both are same... and shared user label must from string.xml

like this example.

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.xxxx" android:versionCode="1" android:versionName="1.0" android:sharedUserId="any string"  android:sharedUserLabel="@string/any_string"> 
like image 182
Ranjithkumar Avatar answered Sep 17 '22 21:09

Ranjithkumar


ContentProviders are a good approach to share data between applications.

like image 40
RoflcoptrException Avatar answered Sep 18 '22 21:09

RoflcoptrException