Multiple apks share data through services and multiple apkservices share data.
1. First, you should
AIDL and remote Service call http://blog.csdn.net/tabactivity/article/details/35832515
2. register the service in AndroidManifest. xml.
<service android:name="com.content.pm.AccountService" android:label="AccountService" android:enabled="true" />
1. If you want the service to be accessible by other applications, you must add
android:enabled="true"
But it will prompt you that this should be added with permission restrictions to ensure his security, so that not all programs can access it at will.
2. Declare Permissions
Add the <manifest> label
<Permission android: protectionLevel = "normal" android: name = "oem. permission. SENDMAIL"> </permission>
Under the <service> label
Android: permission = "oem. permission. SENDMAIL"
Android permission level (protectionLevel) is usually especially sensitive to paid operations and operations that may involve user privacy.
For the above considerations and more security considerations, Android imposes some access restrictions, such as network access (pay-as-you-go) and access to contacts (involving privacy. If the application wants to perform such access, it needs to apply for the corresponding permissions. Android classifies these permissions into four levels. Different Levels of permissions correspond to different authentication methods.
Normal: low-risk permission. You only need to apply for the permission (add the <uses-permission> label to AndroidManifest. xml). You do not need to confirm the permission during installation;
Dangerous: high-risk permissions, which must be confirmed by the user during installation;
Signature: only when the digital signature of the application applying for permission is the same as that of the application declaring this permission (if you apply for system permission, the digital signature must be the same as that of the system ), in order to grant the permission to it;
SignatureOrSystem: the application with the same signature or the permission applied for is a system application (in system image ).
The above four permission levels can also be used for custom permissions. If developers need to control the access of their own applications (or some applications. add the <permission> label to xml, and set the protectionLevel in its attribute to one of the above four levels.
After I modify it here:
<service android:name="com.content.pm.AccountService" android:label="AccountServicee" android:enabled="true" android:exported="true" android:permission="cn.com.talker.permission.ACCESS_ACCOUNT" > </service>
3. In another APK, bind the service and add permissions to access the AIDL method.
Intent mIntent=new Intent(); mIntent.setComponent(new ComponentName("cn.com.talker.beta", "com.content.pm.AccountService"));bindService(mIntent, conn, Context.BIND_AUTO_CREATE);new Thread(new Runnable() { @Override public void run() { String assString; try { Thread.sleep(5000); assString=mAccountService.getAreaCode("aaa")); if(assString!=null){ Log.e("aaaaa", assString); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start();
How to share one data connection with multiple apks
A separate APK is generated for the function of sending and receiving messages over TCP, and corresponding methods are provided. Other projects can use AIDL to remotely call this function in this APK, this will satisfy your requirements.
How to share data between Activity and Service
Well, this is a good question. Many of them learn about android at the beginning. They have no idea about the linux system. It is really easy to confuse the process, thread, class, and class instances. In the native linux system, the process communication mode is socket, but in android, the binder and parcel are integrated, the binder is the remote call mechanism, and the parcel is the remote data sharing mechanism. The principle of intent is to save the data in parcel, and then pass the data through the binder. View Original post>