远程服务调用 PeripheralManager.getInstance [英] remote service call PeripheralManager.getInstance
问题描述
运行时异常:
System.err:java.lang.RuntimeException:存根!在 com.google.android.things.pio.PeripheralManager.getInstance(PeripheralManager.java:21)在 com.afollestad.remotedemo.RemoteService$1.testPeripheralManager(RemoteService.java:33)在 com.afollestad.remotedemo.IRemoteAIDL$Stub.onTransact(IRemoteAIDL.java:56)在 android.os.Binder.execTransact(Binder.java:697)
System.err:java.lang.RuntimeException: Stub! at com.google.android.things.pio.PeripheralManager.getInstance(PeripheralManager.java:21) at com.afollestad.remotedemo.RemoteService$1.testPeripheralManager(RemoteService.java:33) at com.afollestad.remotedemo.IRemoteAIDL$Stub.onTransact(IRemoteAIDL.java:56) at android.os.Binder.execTransact(Binder.java:697)
远程服务的清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.afollestad.remotedemo">
<uses-permission android:name="com.google.android.things.permission.USE_PERIPHERAL_IO" />
<application>
<service
android:name=".RemoteService"
android:process=":remote">
<intent-filter>
<action android:name="service.remote" />
</intent-filter>
</service>
</application>
主要活动:
public class MainActivity extends Activity {
private IRemoteAIDL mService;
private TextView result;
private Button connectRemote;
private Button disconnectRemote;
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
Log.d("aidl", "onServiceConnected" + service + " className " + className);
mService = IRemoteAIDL.Stub.asInterface(service);
try {
mService.testPeripheralManager();
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void onServiceDisconnected(ComponentName className) {
Log.d("aidl", "onServiceDisconnected");
mService = null;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
result = (TextView) findViewById(R.id.result);
connectRemote = (Button) findViewById(R.id.connect_remote);
disconnectRemote = (Button) findViewById(R.id.disconnect_remote);
connectRemote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("aidl", "onClick new thread");
Intent intent = new Intent();
intent.setAction("service.remote");
intent.setPackage("com.afollestad.remotedemo");
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
});
disconnectRemote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("aidl", "onClick");
unbindService(mConnection);
}
});
}}
远程服务:
public class RemoteService extends Service {
private I2cDevice mI2cDevice = null;
private static final String I2C_DEVICE_NAME = "I2C1";
private static final int I2C_ADDRESS = 0x5c;
public Context mContext;
private boolean flag;
@Override
public void onCreate() {
super.onCreate();
}
private final IRemoteAIDL.Stub remoteBinder = new IRemoteAIDL.Stub() {
@Override
public void testPeripheralManager(){
Log.d("aidl", "RemoteService PeripheralManager");
try {
PeripheralManager manager = PeripheralManager.getInstance();
Log.d("aidl", "PeripheralManager2");
mI2cDevice = manager.openI2cDevice(I2C_DEVICE_NAME, I2C_ADDRESS);
if (mI2cDevice != null) Log.i("aidl", "I2C device open successful!");
}catch(RuntimeException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};
@Override
public IBinder onBind(Intent intent) {
Log.d("aidl", "onBind");
mContext = this;
return remoteBinder;
}
@Override
public boolean onUnbind(Intent intent) {
flag = true;
return super.onUnbind(intent);
}
我在android things模块中建立远程服务,在远程服务中调用PeripheralManager.getInstance().
I bulid remote service in android things module, call PeripheralManager.getInstance() in remote service.
如果有人解决了这个问题,请帮助我.
If any solve this problem, Please help me.
推荐答案
你应该有一个 uses-library 作为 Manifest 声明的一部分,这会阻止你在没有 Android Things 的设备中安装需要 Android Things 的 apk它,看起来就是这里发生的事情.
You should have a uses-library as part of the Manifest declaration, that would prevent you from installing an apk that requires Android Things in a device that does not have it, which looks like is what is happening here.
这篇关于远程服务调用 PeripheralManager.getInstance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!