Declare the service in manifest file,
<service android:name=”.ImportExportService” android:enabled=”true”> <intent-filter> <action android:name=”com.test.EXPORT_DATA”/> <action android:name=”com.test.IMPORT_DATA”/> <category android:name=”android.intent.category.DEFAULT” /> </intent-filter> </service>
Add the service class,
public class ImportExportService extends Service{ private static final String TAG = “com.test.ImportExportService”; @Override public IBinder onBind(Intent intent) { return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { if(intent.getAction().equals(“com.test.IMPORT_DATA”)){ Log.i(TAG, “ACTION_IMPORT”); }else if(intent.getAction().equals(“com.test.EXPORT_DATA”)){ Log.i(TAG, “ACTION_EXPORT”); } return 0; } }
Invoke the service from other apps,
Intent intent = new Intent(); intent.setAction(“com.test.IMPORT_DATA”); startService(intent);