Advertisement
Guest User

Untitled

a guest
Jul 14th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. void http3test()
  2.     {
  3.         SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(testActivity.this);
  4.  
  5.         String url = "http://" + appPreferences.getString(String.valueOf(R.string.prefer_share_sip_server), "192.168.1.101") + "/sip.cgi?action=showcalllog";
  6.         okhttp3.OkHttpClient okHttpClient = new okhttp3.OkHttpClient();
  7.         okhttp3.Request request = new okhttp3.Request.Builder()
  8.                 .url(url)
  9.                 .build();
  10.         Call call = okHttpClient.newCall(request);
  11.         call.enqueue(new okhttp3.Callback() {
  12.             @Override
  13.             public void onFailure(Call call, IOException e) {
  14.  
  15.                 runOnUiThread(new Runnable() {
  16.                     @Override
  17.                     public void run() {
  18.                         // Toast.makeText(testActivity.this,"Error",Toast.LENGTH_SHORT).show();
  19.                         Log.d("OKHTTP","Fail");
  20.  
  21.                         String mTmp = String.format("連線超時,直接載入記憶體內容\n\n%s", mDebugTextView.getText().toString());
  22.                         mDebugTextView.setText(mTmp);
  23.                         SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(testActivity.this);
  24.                         String mStr = appPreferences.getString("tmp_ipphone_tel", "");
  25.                         Log.e("IP Phone", "建立List清單");
  26.                         Toast.makeText(testActivity.this,"連線超時",Toast.LENGTH_SHORT).show();
  27.                         InitList(mStr);
  28.  
  29.                     }
  30.                 });
  31.             }
  32.  
  33.             @Override
  34.             public void onResponse(Call call, okhttp3.Response response) throws IOException {
  35.  
  36.                 runOnUiThread(new Runnable() {
  37.                     @Override
  38.                     public void run() {
  39.                         Toast.makeText(testActivity.this,"載入資料成功",Toast.LENGTH_SHORT).show();
  40.                         Log.d("OKHTTP","OK");
  41.                     }
  42.                 });
  43.                 String ret = response.body().string();
  44.                 response.body().close();
  45.                 ProcessHTML(ret);
  46.  
  47.             }
  48.         });
  49.  
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement