- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在检查用户是否打开蓝牙和 GPS 时遇到一些问题。
如果 GPS 关闭,“确定”图标将始终显示 GPS 激活状态。
如果蓝牙已打开,则会显示“确定”图标。但关闭时不会出现“notOK”图标。有人可以检查一下代码吗?
提前致谢!
JAVA类:
LocationManager locationManager;
Button buttongps;
Button buttonblue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_konkurranse);
buttongps = (Button) findViewById(R.id.gps);
buttongps.setOnClickListener(onButtongpsClick);
buttonblue = (Button) findViewById(R.id.bluetooth);
buttonblue.setOnClickListener(onButtonblueClick);
);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
ImageView img = (ImageView) findViewById(R.id.bluestatus);
img.setImageResource(R.drawable.notok);
} else {
if (mBluetoothAdapter.isEnabled()) {
ImageView img = (ImageView) findViewById(R.id.bluestatus);
img.setImageResource(R.drawable.ok);
}
}
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(provider != null){
ImageView img = (ImageView) findViewById(R.id.gpsstatus);
img.setImageResource(R.drawable.ok);
}else{
ImageView img = (ImageView) findViewById(R.id.gpsstatus);
img.setImageResource(R.drawable.notok);
}
}
public View.OnClickListener onButtongpsClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent gpsOptionsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(gpsOptionsIntent);
}
};
public View.OnClickListener onButtonblueClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (!mBluetoothAdapter.isEnabled()) mBluetoothAdapter.enable();
ImageView img = (ImageView) findViewById(R.id.bluestatus);
img.setImageResource(R.drawable.ok);
}
};
// More code below not related, and then removed..
XML 代码。
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp"
android:orientation="vertical"
android:weightSum="1"
android:gravity="top|bottom|center_vertical|fill_vertical|center_horizontal">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="50dp"
android:layout_width="wrap_content"
android:background="@drawable/actionbar"
android:minHeight="?attr/actionBarSize"
android:layout_gravity="center">
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="0.1dp"
android:id="@+id/imageView"
android:src="@drawable/nttop"
android:layout_marginRight="0.94dp"
android:layout_marginLeft="0.06dp"
android:layout_marginBottom="0.05dp"
android:contentDescription="fblogin"
android:scaleType="fitXY" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="SOME test here woop woop"
android:id="@+id/intro"
android:layout_gravity="center_horizontal"
android:layout_marginTop="0.1dp"
android:layout_marginLeft="0.06dp"
android:layout_marginRight="0.94dp"
android:layout_marginBottom="20dp"
android:background="#ffffffff"
android:textSize="20dp"
android:layout_weight="0" />
<LinearLayout
android:layout_width="307dp"
android:layout_height="wrap_content"
android:weightSum="1">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tel"
android:background="@android:color/transparent"
android:src="@drawable/tel"
android:contentDescription="tel"
android:layout_gravity="left|center" />
<EditText
android:layout_width="200dp"
android:layout_height="40dp"
android:inputType="phone"
android:ems="10"
android:id="@+id/mobilnummer"
android:hint="Mobilnummer"
android:textColor="#000000"
android:background="#ffffffff"
android:autoText="false"
android:phoneNumber="false"
android:layout_weight="0.80"
android:layout_marginLeft="20dp"
android:layout_gravity="center_horizontal" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tlfstatus"
android:layout_gravity="right"
android:contentDescription="notok" />
</LinearLayout>
<LinearLayout
android:layout_width="307dp"
android:layout_height="wrap_content"
android:weightSum="1">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gpsicon"
android:src="@drawable/gps"
android:background="@android:color/transparent"
android:contentDescription="gps"
android:layout_gravity="left|center" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Click here for GPS"
android:id="@+id/gps"
android:layout_gravity="center_horizontal"
android:layout_weight="0.76"
android:layout_marginLeft="20dp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/gpsstatus"
android:layout_gravity="right"
android:background="@android:color/transparent"
android:contentDescription="notok" />
</LinearLayout>
<LinearLayout
android:layout_width="307dp"
android:layout_height="wrap_content"
android:weightSum="1">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/blueicon"
android:src="@drawable/bluetooth"
android:background="@android:color/transparent"
android:contentDescription="blue"
android:layout_gravity="left|center" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Bluetooth"
android:id="@+id/bluetooth"
android:layout_weight="0.76"
android:layout_marginLeft="20dp"
android:layout_gravity="center_horizontal" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bluestatus"
android:background="@android:color/transparent"
android:layout_gravity="right"
android:contentDescription="notok" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/info"
android:layout_gravity="bottom|center_horizontal"
android:text="Woop thank you text /fix later " />
</LinearLayout>
<ListView
android:id="@+id/drawer"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="@drawable/menu"
android:layout_width="240dp"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false">
</ListView>
</android.support.v4.widget.DrawerLayout>
最佳答案
我认为检查是错误的。
尝试以下蓝牙检查
final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
final ImageView btImg = (ImageView) findViewById(R.id.bluestatus);
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
btImg.setImageResource(R.drawable.notok);
} else {
btImg.setImageResource(R.drawable.ok);
}
还可以尝试以下 GPS 操作
final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
final ImageView gpsImg = (ImageView) findViewById(R.id.gpsstatus);
if (manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
gpsImg.setImageResource(R.drawable.ok);
} else {
gpsImg.setImageResource(R.drawable.notok);
}
关于java - 检查 GPS 和蓝牙是否已激活时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30712677/
我目前正在使用发现的重力脚本 here为了在我的网页上创建重力效果,我正在本地开发 atm。 我的问题是,重力效果的激活似乎是在鼠标移动时进行的,而我需要它在文档准备好时才触发。 google.cod
我正在尝试关注 Railsbridge Intallfest 并尝试将我的第一个 Rails 应用程序部署到 heroku。我不断收到以下错误消息: Gem::LoadError: Specified
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
Home-tab 是默认选中的,但是它的颜色是灰色的:( Home Bla Contact
我没有得到它的工作,我不知道为什么......遗憾的是其他问题 + 答案没有帮助。 测试设备: iPhone 6 iPad 2 相关代码: override func viewWillTransiti
我试图加载一个 View ,就像用户已经按下 UISearchBar 一样。我希望 SearchController 加载顶部的 UISearchBar 以及取消按钮。 我已经试过了: func ac
试图在 if whiteDotDist < centerRadius - whiteDotRadius 时获取代码执行它下面的所有代码都是事件的,并且当它下面的代码被执行时它再次变为非事件状态直到if
我正在使用 anaconda python。所以每次,在我的 mac 终端中,我输入终端命令: source /Users/mylaptop/anaconda/bin/activate /Users/
在我的 Angular 项目中,我有这种代码: this.swUpdate.available.subscribe(() => { ... }); 它工作正常,但给了我关于 activated 被
我想弄清楚 Julia 包是如何工作的,因为我喜欢容器化环境。我真的很挣扎。 在 python 中,我会做类似 conda create env --name ds 的事情创建环境然后安装容器化包我会
我的宏中有一些代码如下 ChDir File_pth Workbooks.Open filename:= File_pth & "\" & open_tkt Workbooks.Open filena
长话短说,我有两张纸,一张是“原始数据”,另一张是“结果”。我试图让结果表从“原始数据”表的每第七行中提取文本或数字,因此“结果”中的 A1 将是原始数据中的 A1,“结果”中的 A2 将是“原始数据
我不知道如何做到这一点,或者我是否可以做到这一点。我有一个 jQuery UI Accordion,多个部分,每个部分包含多个 anchor 标记,每个 anchor 标记都有一个唯一的字符串 id。
我不敢相信我还没有找到任何关于此的文档,但我想知道如何命令键盘激活并接收来自它的输入。我可以找到在编辑文本字段时操作弹出键盘的所有示例。谢谢 最佳答案 您还可以使用 UIKeyInput 协议(pro
我正在尝试为我的 Electron 应用程序生成NSIS安装程序的日志。为此,我创建了一个文件'logging.nsh'来定义LogSet和LogText宏。 以下是logging.nsh文件的代码:
几周前,我开始使用 typescript 和 knockoutJS,我有一个具体的问题,但我有解决方案,它太丑了,我无法忍受,但无法从中得到任何更好的东西,有太多代码需要粘贴,但我会尽力描述我的问题:
当我尝试激活我的虚拟环境时收到此错误即源 ~/edu-venv/bin/activate -bash: /home/vagrant/edu-venv/bin/activate: No such fil
要创建触发器,似乎必须发布它才能生效。但是发布需要对“协作”分支进行 PR,这意味着我们甚至在测试触发器是否实际工作之前就必须创建一个 PR,并且还必须创建多个后续 PR,直到我们获得正确的触发器。
我是最近的 IntelliJ Idea 用户,我不知道如何启用 Hibernate。当我右键单击我的项目时,Hibernate 不会出现在“添加框架支持”菜单中(实际上我唯一可以选择的技术是 Groo
要创建触发器,似乎必须发布它才能生效。但是发布需要对“协作”分支进行 PR,这意味着我们甚至在测试触发器是否实际工作之前就必须创建一个 PR,并且还必须创建多个后续 PR,直到我们获得正确的触发器。
我是一名优秀的程序员,十分优秀!