简体   繁体   English

蓝牙连接上的自动启动应用程序(android)

[英]autostart app on bluetooth connection (android)

this is more like a general question: 这更像是一个普遍的问题:

Is it possible to create an app, which starts if your phone connects to a specific bluetooth network? 是否可以创建一个应用程序,如果您的手机连接到特定的蓝牙网络,该应用程序将启动?

Is that possible on android? 在Android上可能吗? If yes, is there any documentation for a start? 如果是,是否有任何入门文档?

They use a BroadcastReceiver for bluetooth like in this article , from which you can do whatever you want. 他们像本文中一样将BroadcastReceiver用于蓝牙,您可以从中做任何您想做的事情。 (like launching a new activity or whatever) (例如发起新活动或其他活动)

here's a small stackoverflow thread about this. 这是关于此的一个小型stackoverflow线程

In my opinion it is impossible to do that in that way. 我认为不可能那样做。 Generaly possible is another scenario. 通常可能是另一种情况。 Application still works in background and monit if device connect to network. 如果设备连接到网络,则应用程序仍可在后台运行并进行监视。 If that happend than can fire another action. 如果发生这种情况,可以采取其他行动。

Like nadavfima said, you'll need to use a BroadcastReceiver to listen for Bluetooth connections. 就像nadavfima所说的那样,您需要使用BroadcastReceiver来侦听蓝牙连接。 When it triggers, you can extract the name of the device that just connected. 触发时,您可以提取刚刚连接的设备的名称。 If that name matches your criteria, then do whatever you want (Launch a new activity etc.) 如果该名称符合您的条件,那么您可以做任何想做的事情(启动新活动等)

What they didn't explain is that you need to have your app start a Service, which will register the BroadcastReceiver. 他们没有解释的是,您需要让您的应用启动服务,该服务将注册BroadcastReceiver。

-User installs your app and launches it. -用户安装并启动您的应用程序。

-Button to toggle the service on/off -按钮以打开/关闭服务

-User closes your app, but service continues to run -用户关闭您的应用程序,但服务继续运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM