@@ -129,7 +129,7 @@ private void startSignalLevelListener() {
129
129
TelephonyManager tm = (TelephonyManager ) getSystemService (TELEPHONY_SERVICE );
130
130
int events = PhoneStateListener .LISTEN_SIGNAL_STRENGTH
131
131
| PhoneStateListener .LISTEN_DATA_ACTIVITY
132
- | PhoneStateListener .LISTEN_CELL_LOCATION
132
+ // | PhoneStateListener.LISTEN_CELL_LOCATION
133
133
| PhoneStateListener .LISTEN_CALL_STATE
134
134
| PhoneStateListener .LISTEN_CALL_FORWARDING_INDICATOR
135
135
| PhoneStateListener .LISTEN_DATA_CONNECTION_STATE
@@ -262,15 +262,15 @@ public void onCallForwardingIndicatorChanged(boolean cfi) {
262
262
public void onCallStateChanged (int state , String incomingNumber ) {
263
263
String callState = "UNKNOWN" ;
264
264
switch (state ) {
265
- case TelephonyManager .CALL_STATE_IDLE :
266
- callState = "IDLE" ;
267
- break ;
268
- case TelephonyManager .CALL_STATE_RINGING :
269
- callState = "Ringing (" + incomingNumber + ")" ;
270
- break ;
271
- case TelephonyManager .CALL_STATE_OFFHOOK :
272
- callState = "Offhook" ;
273
- break ;
265
+ case TelephonyManager .CALL_STATE_IDLE :
266
+ callState = "IDLE" ;
267
+ break ;
268
+ case TelephonyManager .CALL_STATE_RINGING :
269
+ callState = "Ringing (" + incomingNumber + ")" ;
270
+ break ;
271
+ case TelephonyManager .CALL_STATE_OFFHOOK :
272
+ callState = "Offhook" ;
273
+ break ;
274
274
}
275
275
setTextViewText (info_ids [INFO_CALL_STATE_INDEX ], callState );
276
276
Log .i (APP_NAME , "onCallStateChanged " + callState );
@@ -283,28 +283,38 @@ public void onCellLocationChanged(CellLocation location) {
283
283
setTextViewText (info_ids [INFO_CELL_LOCATION_INDEX ], locationString );
284
284
285
285
Log .i (APP_NAME , "onCellLocationChanged " + locationString );
286
+ if (ActivityCompat .checkSelfPermission (TelephonyManagerDemo .this , Manifest .permission .ACCESS_FINE_LOCATION ) != PackageManager .PERMISSION_GRANTED ) {
287
+ // TODO: Consider calling
288
+ // ActivityCompat#requestPermissions
289
+ // here to request the missing permissions, and then overriding
290
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
291
+ // int[] grantResults)
292
+ // to handle the case where the user grants the permission. See the documentation
293
+ // for ActivityCompat#requestPermissions for more details.
294
+ return ;
295
+ }
286
296
super .onCellLocationChanged (location );
287
297
}
288
298
289
299
@ Override
290
300
public void onDataActivity (int direction ) {
291
301
String directionString = "none" ;
292
302
switch (direction ) {
293
- case TelephonyManager .DATA_ACTIVITY_IN :
294
- directionString = "IN" ;
295
- break ;
296
- case TelephonyManager .DATA_ACTIVITY_OUT :
297
- directionString = "OUT" ;
298
- break ;
299
- case TelephonyManager .DATA_ACTIVITY_INOUT :
300
- directionString = "INOUT" ;
301
- break ;
302
- case TelephonyManager .DATA_ACTIVITY_NONE :
303
- directionString = "NONE" ;
304
- break ;
305
- default :
306
- directionString = "UNKNOWN: " + direction ;
307
- break ;
303
+ case TelephonyManager .DATA_ACTIVITY_IN :
304
+ directionString = "IN" ;
305
+ break ;
306
+ case TelephonyManager .DATA_ACTIVITY_OUT :
307
+ directionString = "OUT" ;
308
+ break ;
309
+ case TelephonyManager .DATA_ACTIVITY_INOUT :
310
+ directionString = "INOUT" ;
311
+ break ;
312
+ case TelephonyManager .DATA_ACTIVITY_NONE :
313
+ directionString = "NONE" ;
314
+ break ;
315
+ default :
316
+ directionString = "UNKNOWN: " + direction ;
317
+ break ;
308
318
}
309
319
310
320
setDataDirection (info_ids [INFO_DATA_DIRECTION_INDEX ], direction );
@@ -316,22 +326,22 @@ public void onDataActivity(int direction) {
316
326
public void onDataConnectionStateChanged (int state ) {
317
327
String connectionState = "Unknown" ;
318
328
switch (state ) {
319
- case TelephonyManager .DATA_CONNECTED :
320
- connectionState = "Connected" ;
321
- break ;
322
- case TelephonyManager .DATA_CONNECTING :
323
- connectionState = "Connecting" ;
324
- break ;
325
- case TelephonyManager .DATA_DISCONNECTED :
326
- connectionState = "Disconnected" ;
327
- break ;
328
- case TelephonyManager .DATA_SUSPENDED :
329
- connectionState = "Suspended" ;
330
- break ;
331
- default :
332
-
333
- connectionState = "Unknown: " + state ;
334
- break ;
329
+ case TelephonyManager .DATA_CONNECTED :
330
+ connectionState = "Connected" ;
331
+ break ;
332
+ case TelephonyManager .DATA_CONNECTING :
333
+ connectionState = "Connecting" ;
334
+ break ;
335
+ case TelephonyManager .DATA_DISCONNECTED :
336
+ connectionState = "Disconnected" ;
337
+ break ;
338
+ case TelephonyManager .DATA_SUSPENDED :
339
+ connectionState = "Suspended" ;
340
+ break ;
341
+ default :
342
+
343
+ connectionState = "Unknown: " + state ;
344
+ break ;
335
345
}
336
346
337
347
setTextViewText (info_ids [INFO_CONNECTION_STATE_INDEX ],
@@ -345,6 +355,16 @@ public void onDataConnectionStateChanged(int state) {
345
355
@ Override
346
356
public void onMessageWaitingIndicatorChanged (boolean mwi ) {
347
357
Log .i (APP_NAME , "onMessageWaitingIndicatorChanged " + mwi );
358
+ if (ActivityCompat .checkSelfPermission (TelephonyManagerDemo .this , Manifest .permission .READ_PHONE_STATE ) != PackageManager .PERMISSION_GRANTED ) {
359
+ // TODO: Consider calling
360
+ // ActivityCompat#requestPermissions
361
+ // here to request the missing permissions, and then overriding
362
+ // public void onRequestPermissionsResult(int requestCode, String[] permissions,
363
+ // int[] grantResults)
364
+ // to handle the case where the user grants the permission. See the documentation
365
+ // for ActivityCompat#requestPermissions for more details.
366
+ return ;
367
+ }
348
368
super .onMessageWaitingIndicatorChanged (mwi );
349
369
}
350
370
0 commit comments