Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. package com.tmobile.pr.mytmobile;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.os.AsyncTask;
  6. import android.os.Bundle;
  7. import android.telephony.AccessNetworkConstants;
  8. import android.telephony.CellInfo;
  9. import android.telephony.NetworkScanRequest;
  10. import android.telephony.RadioAccessSpecifier;
  11. import android.telephony.TelephonyManager;
  12. import android.telephony.TelephonyScanManager;
  13. import android.util.Log;
  14. import android.view.View;
  15. import android.widget.Button;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18.  
  19. import java.util.List;
  20.  
  21. public class MainActivity extends Activity implements View.OnClickListener {
  22.  
  23. private static final String TAG = "MainActivity";
  24.  
  25. private TextView textView;
  26.  
  27. private class ResponseCallback extends TelephonyScanManager.NetworkScanCallback {
  28. private List<CellInfo> mCellInfoResults;
  29. private int mOnError;
  30.  
  31. @Override
  32. public void onResults(List<CellInfo> cellInfoResults) {
  33. this.mCellInfoResults = cellInfoResults;
  34. MainActivity.this.runOnUiThread(new Runnable() {
  35. @Override
  36. public void run() {
  37. for (CellInfo cellInfo : ResponseCallback.this.mCellInfoResults) {
  38. Log.d(TAG, "run: onResults");
  39. textView.append(" " + cellInfo.toString() + " ");
  40. }
  41. }
  42. });
  43. }
  44.  
  45. @Override
  46. public void onError(int error) {
  47. mOnError = error;
  48. MainActivity.this.runOnUiThread(new Runnable() {
  49. @Override
  50. public void run() {
  51. Log.d(TAG, "run: onError");
  52. textView.append(" Error: " + mOnError);
  53. }
  54. });
  55. }
  56.  
  57. @Override
  58. public void onComplete() {
  59. MainActivity.this.runOnUiThread(new Runnable() {
  60. @Override
  61. public void run() {
  62. Log.d(TAG, "run: onComplete");
  63. textView.append(" onComplete ");
  64. }
  65. });
  66. }
  67. }
  68.  
  69. @Override
  70. protected void onCreate(Bundle savedInstanceState) {
  71. super.onCreate(savedInstanceState);
  72. setContentView(R.layout.activity_main);
  73. Button buttonMain = findViewById(R.id.button_main);
  74. buttonMain.setOnClickListener(this);
  75. textView = findViewById(R.id.tv1);
  76. }
  77.  
  78.  
  79. public void onClick(View view) {
  80.  
  81. Log.d(TAG, "onClick: MainActivity");
  82.  
  83. Toast.makeText(this, "Click context", Toast.LENGTH_SHORT).show();
  84.  
  85. NetworkScanRequest networkScanRequest;
  86. RadioAccessSpecifier[] radioAccessSpecifiers;
  87.  
  88.  
  89. TelephonyManager tManager = (TelephonyManager) getApplicationContext()
  90. .getSystemService(Context.TELEPHONY_SERVICE);
  91.  
  92. radioAccessSpecifiers = new RadioAccessSpecifier[1];
  93. radioAccessSpecifiers[0] = new RadioAccessSpecifier(
  94. AccessNetworkConstants.AccessNetworkType.EUTRAN,
  95. null,
  96. null);
  97.  
  98. networkScanRequest = new NetworkScanRequest(
  99. NetworkScanRequest.SCAN_TYPE_PERIODIC,
  100. radioAccessSpecifiers,
  101. /**
  102. * Search periodicity (in seconds).
  103. * Expected range for the input is [5s - 300s]
  104. * This value must be less than or equal to mMaxSearchTime
  105. */
  106. 30,
  107. /**
  108. * Maximum duration of the periodic search (in seconds).
  109. * Expected range for the input is [60s - 3600s] //[1m - 1hr]
  110. * If the search lasts this long, it will be terminated.
  111. */
  112. 300,
  113. /**
  114. * Indicates whether the modem should report incremental
  115. * results of the network scan to the client.
  116. * FALSE – Incremental results are not reported.
  117. * TRUE (default) – Incremental results are reported
  118. */
  119. true,
  120. /**
  121. * Indicates the periodicity with which the modem should
  122. * report incremental results to the client (in seconds).
  123. * Expected range for the input is [1s - 10s]
  124. * This value must be less than or equal to mMaxSearchTime
  125. */
  126. 3,
  127. null);
  128.  
  129. tManager.requestNetworkScan(networkScanRequest, AsyncTask.SERIAL_EXECUTOR, new ResponseCallback());
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement