remote service call PeripheralManager.getInstance

Internet of Things IoT Frameworks . 2 years ago

  0   1   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 5 Rating
_x000D_ _x000D_ run time exception: 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) Remote service's Manifest file: MainActivity: 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); } }); }} remote service: 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); } I bulid remote service in android things module, call PeripheralManager.getInstance() in remote service. If any solve this problem, Please help me.

Posted on 16 Aug 2022, this text provides information on IoT Frameworks related to Internet of Things. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Write Your Comments or Explanations to Help Others



Tuteehub forum answer Answers (1)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ 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.
0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Internet of Things Links

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community