Skip to content

Commit 4627e33

Browse files
len konglen kong
len kong
authored and
len kong
committed
demo signal streagth and identify
1 parent 4ee3d78 commit 4627e33

File tree

3 files changed

+64
-23
lines changed

3 files changed

+64
-23
lines changed

app/src/main/java/com/lennoo/rno/MainActivity.java

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.lennoo.rno;
22

33
import android.content.Context;
4+
import android.content.Intent;
45
import android.os.Build;
56
import android.support.v7.app.AppCompatActivity;
67
import android.os.Bundle;
8+
import android.telephony.CellInfo;
79
import android.telephony.CellInfoGsm;
10+
import android.telephony.CellInfoLte;
811
import android.telephony.CellSignalStrengthGsm;
912
import android.telephony.TelephonyManager;
1013
import android.view.ViewDebug;
@@ -30,6 +33,9 @@ protected void onCreate(Bundle savedInstanceState) {
3033
TextView textDataState = (TextView)findViewById(R.id.datastate);
3134
TextView textDataActivity = (TextView)findViewById(R.id.dataactivity);
3235
TextView textGsmSign = (TextView)findViewById(R.id.gsmsign);
36+
TextView textTac = (TextView)findViewById(R.id.tac);
37+
TextView textPci = (TextView)findViewById(R.id.pci);
38+
TextView textRsrp = (TextView)findViewById(R.id.rsrp);
3339

3440
textPhoneModel.setText("手机:"+Build.MODEL);
3541
textSystemVer.setText("系统:"+Build.VERSION.RELEASE);
@@ -40,10 +46,22 @@ protected void onCreate(Bundle savedInstanceState) {
4046
textDataState.setText("数据状态:"+telephonyInfo.getDataState());
4147
textDataActivity.setText("数据活动:"+telephonyInfo.getDataActivity());
4248

43-
TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
44-
CellInfoGsm cellinfogsm = (CellInfoGsm)telephonyManager.getAllCellInfo().get(0);
45-
CellSignalStrengthGsm cellSignalStrengthGsm = cellinfogsm.getCellSignalStrength();
46-
int gsmsign = cellSignalStrengthGsm.getDbm();
47-
textGsmSign.setText("Sign"+ Integer.toString(gsmsign));
49+
TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
50+
CellInfo cellinfo = tm.getAllCellInfo().get(0);
51+
int sign = 0;
52+
int ta = 0;
53+
int tac = 0;
54+
if (cellinfo instanceof CellInfoGsm) {
55+
sign = ((CellInfoGsm)cellinfo).getCellSignalStrength().getDbm();
56+
} else if (cellinfo instanceof CellInfoLte) {
57+
CellInfoLte cellInfoLte = (CellInfoLte)cellinfo;
58+
sign = cellInfoLte.getCellSignalStrength().getDbm();
59+
ta = cellInfoLte.getCellSignalStrength().getTimingAdvance();
60+
tac = cellInfoLte.getCellIdentity().getTac();
61+
62+
}
63+
textGsmSign.setText("Sign"+ Integer.toString(sign));
64+
textPci.setText("TA:"+Integer.toString(ta));
65+
textTac.setText("TAC:"+ Integer.toString(tac));
4866
}
4967
}

app/src/main/res/layout/activity_main.xml

+24
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,30 @@
107107
android:layout_height="wrap_content"
108108
android:orientation="horizontal">
109109

110+
<TextView
111+
android:layout_width="match_parent"
112+
android:layout_height="match_parent"
113+
android:id="@+id/tac"
114+
android:layout_weight="1"
115+
android:text="LAC:"/>
116+
<TextView
117+
android:layout_width="match_parent"
118+
android:layout_height="match_parent"
119+
android:id="@+id/pci"
120+
android:layout_weight="1"
121+
android:text="CID:"/>
122+
<TextView
123+
android:layout_width="match_parent"
124+
android:layout_height="match_parent"
125+
android:id="@+id/rsrp"
126+
android:layout_weight="1"
127+
android:text="Sign:"/>
128+
</LinearLayout>
129+
<LinearLayout
130+
android:layout_width="match_parent"
131+
android:layout_height="wrap_content"
132+
android:orientation="horizontal">
133+
110134
<TextView
111135
android:layout_width="match_parent"
112136
android:layout_height="match_parent"

gradle.properties

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
# Project-wide Gradle settings.
2-
3-
# IDE (e.g. Android Studio) users:
4-
# Gradle settings configured through the IDE *will override*
5-
# any settings specified in this file.
6-
7-
# For more details on how to configure your build environment visit
8-
# http://www.gradle.org/docs/current/userguide/build_environment.html
9-
10-
# Specifies the JVM arguments used for the daemon process.
11-
# The setting is particularly useful for tweaking memory settings.
12-
# Default value: -Xmx10248m -XX:MaxPermSize=256m
13-
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14-
15-
# When configured, Gradle will run in incubating parallel mode.
16-
# This option should only be used with decoupled projects. More details, visit
17-
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18-
# org.gradle.parallel=true
1+
## Project-wide Gradle settings.
2+
#
3+
# For more details on how to configure your build environment visit
4+
# http://www.gradle.org/docs/current/userguide/build_environment.html
5+
#
6+
# Specifies the JVM arguments used for the daemon process.
7+
# The setting is particularly useful for tweaking memory settings.
8+
# Default value: -Xmx10248m -XX:MaxPermSize=256m
9+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10+
#
11+
# When configured, Gradle will run in incubating parallel mode.
12+
# This option should only be used with decoupled projects. More details, visit
13+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14+
# org.gradle.parallel=true
15+
#Mon Sep 19 21:30:14 CST 2016
16+
systemProp.http.proxyHost=127.0.0.1
17+
systemProp.http.proxyPort=1080

0 commit comments

Comments
 (0)