我知道这里还有另一个与此有关的问题,但是我认为这不适用于我,因为我敢肯定我使用的是GSM(isGSM()返回true)。无论如何,无论如何getCdmaDbm都会为我返回-1。我正在使用Android 4.1.1和HTC OneX。这是我的代码(其中大多数不是我的):
主要活动:
package com.example.receptionlookup;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends Activity {
TelephonyManager Tel;
MyPhoneStateListener MyListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* Update the listener, and start it */
MyListener = new MyPhoneStateListener();
Tel = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
/* Called when the application is minimized */
@Override
protected void onPause()
{
super.onPause();
Tel.listen(MyListener, PhoneStateListener.LISTEN_NONE);
}
/* Called when the application resumes */
@Override
protected void onResume()
{
super.onResume();
Tel.listen(MyListener,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
}
/* —————————– */
/* Start the PhoneState listener */
/* —————————– */
private class MyPhoneStateListener extends PhoneStateListener
{
/* Get the Signal strength from the provider, each tiome there is an update */
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
super.onSignalStrengthsChanged(signalStrength);
Toast.makeText(getApplicationContext(), "Go to Firstdroid!!! GSM Cinr = "
+ String.valueOf(signalStrength.getGsmSignalStrength()), Toast.LENGTH_SHORT).show();
}
};/* End of private Class */
}
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.receptionlookup"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.receptionlookup.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
</manifest>
有人知道问题出在哪里吗?如果我转到“设置”->“关于”->“网络”,则可以在那里看到信号强度。有没有办法读取这个值?我已经尝试了几种第三方应用程序,但它们都无法读取我的信号强度。我也尝试了专有的getGSMSignalBar()方法,但遇到了NoSuchMethodException。
参考方案
正如您可以在3GPP 127 007 8.5中阅读的那样,at+csq
的实现是可选的(假设该命令给出信号强度)。显然,HTC对第三方应用程序隐藏了该值,并且他们可能还有另一种方法来实现该值,以便在自己的专有“设置”应用程序中显示。
其他应用程序也无法获取该信息的事实证明了我的观点。
This issue与您紧密相关-泰伊说,HTC是不值得与调制解调器相关的开发时间的OEM之一。
Android:如何为wrap_content设置高度动画? - java我需要使用ValueAnimator来使用户拖动特定视图时出现自定义“放置字段”。 (我想将字段从gone, height = 0更改为visible, height = wrap_content)。我已经尝试过以下问题的解决方案:How to animate to wrap_content?当我在单个TextView上使用它时,答案就起作用了,但是当我尝试…
为什么我的应用在启动时总是崩溃-Android - java刚刚遵循了有关如何制作按钮和活动的youtube指南。我按照他的代码减小字体大小,并且在启动时一直崩溃。有人知道为什么吗?public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { su…
android-android studio模拟器中的SSL问题,在手机上可以正常工作 - java我有一个可以通过https调用网络服务的应用程序。当我在手机上运行apk时,效果很好。但是,在模拟器中,所有通过POST的SSL请求均失败,并显示以下信息: 读取错误:ssl = 0xb402be00:SSL库失败,通常是一个协议 错误 错误:100c50bf:SSL例程:ssl3_read_bytes:NO_RENEGOTIATION(外部/无聊的sl /…
如何在ScrollView和LinearLayout中居中 - java请看下面的代码<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match…
绑定Java库Xamarin.Android - java我花了两天时间在每个论坛,文档,tuto,博客等上寻找答案。我为实习生启动了一个Android应用程序,因为我不懂Java,所以用xamarin C#开发了它。直到最近一切都还不错,但现在我需要集成一个SDK才能在应用程序中使用POS(销售点),但是该库是用Java编写的,即使跟随文档或辅导老师,我也无法将其与xamarin绑定(我什至无法调试)。这里有人已…