【发布时间】:2017-05-21 22:53:21
【问题描述】:
当连接了一些蓝牙设备时,如何在我的安卓手机中启动应用程序?
我正在尝试使用广播接收器执行此操作,但我有一个问题......当我完成活动(退出应用程序)时,广播接收器必须取消注册......所以无法收听连接的设备...
应用程序完成后,如何让这个广播接收器保持活动状态?
谢谢
编辑:
public class AutostartReceiver extends BroadcastReceiver
{
/**
* @param context Context
* @param intent Intent
* @return void
*/
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
switch (action)
{
case BluetoothDevice.ACTION_ACL_CONNECTED:
Log.v("PAREK", "cnn");
break;
case BluetoothDevice.ACTION_ACL_DISCONNECTED:
Log.v("PAREK", "dnn");
break;
}
}
}
我也尝试了清单初始化
<receiver
android:name=".Model.Tools.AutostartReceiver">
<intent-filter>
<action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED" />
<action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED" />
<action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECTED" />
</intent-filter>
</receiver>
编辑2:
为什么?因为我希望我的应用程序只能在汽车上运行...所以当应用程序连接到汽车免提时,应用程序将启动...并且在断开连接 5 分钟后,应用程序将“终止”。
【问题讨论】:
标签: android bluetooth broadcastreceiver