-
Notifications
You must be signed in to change notification settings - Fork 0
/
AidlClientCode.java
55 lines (42 loc) · 1.63 KB
/
AidlClientCode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.mx.testaidl;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.mx.aidl.easytouch.IRemoteFavService;
import com.mx.aidl.easytouch.FavorApp;
public class MainActivity extends AppCompatActivity {
private IRemoteFavService service;
private RemoteServiceConnection serviceConnection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
connectService();
}
private void connectService() {
serviceConnection = new RemoteServiceConnection();
Intent i = new Intent("com.mx.easytouch.service.FavorAppService");
i.setPackage("com.mx.easytouch");
boolean ret = bindService(i, serviceConnection, Context.BIND_AUTO_CREATE);
}
class RemoteServiceConnection implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName name, IBinder binderservice) {
service = IRemoteFavService.Stub.asInterface((IBinder) binderservice);
try {
Toast.makeText(MainActivity.this, service.getFavor().get(0).getName(), Toast.LENGTH_SHORT).show();
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
}
}