小编tor*_*aro的帖子

即使应用程序关闭(已杀死)也运行服务

我希望即使应用程序已关闭(kiiled)或即使用户不启动应用程序,此服务也会运行.我希望在安装应用程序后启动服务,从这一点开始,服务应该始终运行.

public class notifications extends Service {

        @Override
        public IBinder onBind(Intent intent) {
                // TODO Auto-generated method stub
                return null;
        }

        @Override
    public void onCreate() {
    }

    @Override
    public void onStart(Intent intent, int startId) {
                final Handler handler = new Handler();
                final Runnable runb = new Runnable()
                {
                    public void run()
                    {
                        Toast.makeText(getApplicationContext(), " Service Started", Toast.LENGTH_LONG).show();
                        handler.postDelayed(this, 10000);
                    }
                };
                handler.postDelayed(runb, 0);

    }
    @Override
    public void onDestroy() {

    }
}*/

public class notifications extends IntentService
{
        private Timer mBackGroundTimer; …
Run Code Online (Sandbox Code Playgroud)

service android background

15
推荐指数
3
解决办法
3万
查看次数

扫描蓝牙设备

我有一个BroadcastReceiver,我想要一直扫描蓝牙设备.我想找到是否有设备名称X,如果他在附近(如果applcation发现这个设备有蓝牙),我想做点什么.

所以,我只需要总是扫描设备的方式,而不是停止,我可以做其余的事情.

谢谢!

android bluetooth broadcastreceiver network-scan

2
推荐指数
1
解决办法
1949
查看次数