Android手机应用程序,一旦它被连接或断开蓝牙设备始终得到重启 [英] Android mobile app always get restarted once it is connected or disconnected to bluetooth device

查看:1057
本文介绍了Android手机应用程序,一旦它被连接或断开蓝牙设备始终得到重启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有Android原生多标签栏code,其中包含酒吧code领域的蓝牙设备进入酒吧code应用程序。当午餐这种移动时,它首先有一个弹出窗口让用户选择的选项卡。问题是,每当蓝牙设备连接或断开到移动时,应用程序总是得到重新共进午餐这个弹出窗口。我们怎样才能停止移动时,蓝牙设备连接或断开重新开始?

我附加了AndroidManifest.xml中:

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.mentor.med.mobile
    安卓版code =1
    机器人:=的versionName1.0.1>
    <用途-SDK
        安卓的minSdkVersion =11
        机器人:targetSdkVersion =17/>
        <使用许可权的android:NAME =android.permission.CAMERA/>
    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/中
        机器人:标签=@字符串/ APP_NAME
        机器人:screenOrientation =sensorPortrait
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名字=com.pdx.MainActivity
            机器人:configChanges =keyboardHidden |方向|屏幕尺寸
            机器人:windowSoftInputMode =adjustPan
            机器人:launchMode =singleTop
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>
                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.VIEW/>
                <类机器人:名字=android.intent.category.DEFAULT/>
                <类机器人:名字=android.intent.category.BROWSABLE/>
                <数据机器人:计划=HTTP机器人:主机=pdx.com机器人:PATH =/视图/>
            &所述; /意图滤光器>
        < /活性GT;
        <活动
            机器人:名字=com.google.zxing.client.android.CaptureActivity
            机器人:configChanges =方向| keyboardHidden
            机器人:screenOrientation =风景
            机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen
            机器人:windowSoftInputMode =stateAlwaysHidden>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>
                <类机器人:名字=android.intent.category.DEFAULT/>
            &所述; /意图滤光器>
            &所述;意图滤光器>
                <作用机器人:名字=com.google.zxing.client.android.SCAN/>
                <类机器人:名字=android.intent.category.DEFAULT/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>
< /清单>


解决方案

应用程序可能注册一个广播接收器,监听连接的蓝牙设备。这种接收器然后启动一个弹出式的活动。您有几种选择:

的一个解决方案可以是,除去在所注册的意图过滤器到接收器清单文件中的条目(它可能是一个活动)。但很明显,那么应用程序将不会自动在蓝牙设备连接启动。

另外,你可能想改变接收器的逻辑,所以它会检查是否在活动前重新打开它已经打开。一种方法是做到这一点的活动本身:这取决于你如何希望应用程序时,您可能需要更改 launchMode =singleTop,并使用重写方法如 isFinishing() onNewIntent()来确定应用程序是否正在重新启动,以及为什么。

We have Android native multiple tab barcode application which contains barcode field for Bluetooth device to enter the barcode. When lunch this mobile, it first have one popup to let user to select the tab. The problem is that every time when the bluetooth device is connected or disconnected to the mobile, the application always get re-lunched with this popup. How can we stop mobile to re-start when the bluetooth device is connected or disconnected?

I'm attaching the AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mentor.med.mobile"
    android:versionCode="1"
    android:versionName="1.0.1" >
    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="17" />
        <uses-permission android:name="android.permission.CAMERA" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/med"
        android:label="@string/app_name"
        android:screenOrientation="sensorPortrait"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.pdx.MainActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustPan"
            android:launchMode="singleTop"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="http" android:host="pdx.com" android:path="/view" />
            </intent-filter>
        </activity>            
        <activity
            android:name="com.google.zxing.client.android.CaptureActivity"
            android:configChanges="orientation|keyboardHidden"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="stateAlwaysHidden" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <intent-filter>
                <action android:name="com.google.zxing.client.android.SCAN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

解决方案

The application probably registers a broadcast receiver, which listens for bluetooth devices being connected. That receiver then launches the Activity with a popup. You have a few options:

One solution could be to remove the entry in the manifest file which registers the intent filter to a receiver (it could be an activity). But obviously then the app will never launch automatically when Bluetooth devices are connected.

Alternatively, you probably want to change the logic of the receiver so it checks if the activity is already open before re-opening it. One way would be to do this in the Activity itself: depending on how you want the application to behave, you may need to change launchMode="singleTop", and use override methods such as isFinishing(), onNewIntent() to determine if the application is restarting and why.

这篇关于Android手机应用程序,一旦它被连接或断开蓝牙设备始终得到重启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆