2012-04-24 28 views
2

對於許可證檢查,如果傳遞「未許可」響應,但沒有或低連接,我一直在嘗試解決。我想檢查信號強度,如果它超過50%(15)或由於沒有連接而返回99,我希望它繞過檢查,直到下次以更好的信號啓動應用程序。通過這種方式,任何授權用戶都不應該看到NOT LICENSED響應。getGsmSignalStrength()總是返回'99'

問題1:使用getGsmSignalStrength()時,只返回phone/3g/4g強度或wifi強度。如果用戶使用的是WiFi模式,那麼它應該可以工作?我知道如何檢查WiFi是否連接,所以如果需要的話,我總是可以使用它來檢查WiFi。

問題2:getGsmSignalStrength()總是返回'99'的值,即使當我盯着我的手機,它顯示出完整的實力。

ConnecetivityCheck.java的全部目的是檢查然後繼續。現在我只是自動跳過檢查並顯示帶有getGsmSignalStrength()數字的Toast框,但這總是顯示'99'。

請幫助,謝謝。 下面我重視我的代碼...

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.emsprotocols.ilpaemsprotocols" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="7" /> 

<!-- PERMISSIONS --> 
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission> 
<uses-permission android:name="android.permission.INTERNET"></uses-permission> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 


<!-- LICENSE PERMISSIONS --> 
<uses-permission android:name="com.android.vending.CHECK_LICENSE" /> 

<!-- USES --> 
<uses-feature android:name="android.hardware.telephony" android:required="false"/> 

<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> 
    <activity android:name=".ProtocolsSplashActivity" 
       android:label="@string/app_name"> 
     <intent-filter> 

的java文件

package com.emsprotocols.ilpaemsprotocols; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.telephony.PhoneStateListener; 
import android.telephony.SignalStrength; 
import android.telephony.TelephonyManager; 
import android.widget.Toast; 

public class ConnectivityCheck extends Activity { 
TelephonyManager  Tel; 
MyPhoneStateListener MyListener; 

@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle);   

    /* Update the listener, and start it */ 
    MyListener = new MyPhoneStateListener(); 
    Tel  = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
    Tel.listen(MyListener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS); 

     startActivity(new Intent(this, ProtocolsMMenuActivity.class)); 
     ConnectivityCheck.this.finish(); 
} 

/* 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) 
    { 
     int strengthAmplitude = signalStrength.getGsmSignalStrength(); 

     super.onSignalStrengthsChanged(signalStrength); 
     Toast.makeText(getApplicationContext(), "GSM Cinr = " 
     + String.valueOf(strengthAmplitude), Toast.LENGTH_SHORT).show(); 
    } 

};/* End of private Class */ 

} 

回答

1

問題1:它應該只有GSM的信號強度。

問題2:我找不到你的代碼有什麼問題,你確定你有GSM信號嗎?如果你住在美國,那麼你更可能使用CDMA網絡。還有其他方法可以獲得信號強度:Link

+0

我在美國。 DOH!那麼這也可以解釋爲什麼它只會出現99. LOL。謝謝。它總是你看過的小事。你知道CDMA的範圍嗎? – djmedic 2012-04-24 20:08:47

+0

沒有抱歉,但該信息不應該太難找到。祝你好運! – Heinrisch 2012-04-24 20:42:34

+0

CDMA的範圍是什麼?它總是負的dBm,所以不知道這是如何工作的百分比。 – JPM 2013-01-09 20:49:21