安卓 5.0 之后启动服务,必须是显式的,startService()。安卓不能启动服务

1.当按照正规启动不了服务的时候,可以试试以下方法:

  Intent intent = new Intent("com.gnss.GNSSService");
  intent.setAction(GPSBOARDCONTROL);//Service能够匹配的Action
  intent.setPackage("com.gnss.ssserver");//应用的包名
  context.startService(intent);


2. 上面是安卓 5.0 之后显式开启服务的一个写法,但是,有时候可能启动不了服务,所以可以试用下面的方法。

Intent intent = new Intent();

intent.setClass(mActivity,TestService.class);

// mActivity是当前的activity,TestService.class是要启动的服务

mActivity.startService(intent);

猜你喜欢

转载自blog.csdn.net/song91425/article/details/79609552