Beispiel #1
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    rq = Volley.newRequestQueue(getApplicationContext());
    if (Util.isNetworkConnected(this)) {
      new Thread(getMessage).start();
      ThreadNum++;
      Log.v("ThreadNum++", ThreadNum + "");
    } else {
      Toast.makeText(this, "网络不可用", Toast.LENGTH_LONG).show();
    }

    return super.onStartCommand(intent, flags, startId);
  }
Beispiel #2
0
  private void sendRequest() {
    String url;
    String mac = Util.getWIFIMac(this);
    String appName;

    try {
      appName =
          URLEncoder.encode(PushService.this.getResources().getString(R.string.app_name), "UTF-8");
      url =
          "http://112.124.33.125/appInClient/GetUserInfo?sclientmac="
              + mac
              + "&sAppName="
              + appName;
      Log.v("url", url);
      StringRequest jr =
          new StringRequest(
              url,
              new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                  Log.v("response", Util.UnicodeToString(response));

                  try {
                    result = gson.fromJson(Util.UnicodeToString(response), Info.class);
                  } catch (JsonSyntaxException e) {
                    result = new Info();
                    result.status = "0";
                    e.printStackTrace();
                  }
                  Handler handler = new Handler();

                  handler.post(notify);
                }
              },
              new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                  Toast.makeText(PushService.this, "接口调用错误", Toast.LENGTH_SHORT).show();
                  Log.d("onErrorResponse", "接口调用错误");
                  Log.d("onErrorResponse", "", error);
                }
              });

      rq.add(jr);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Beispiel #3
0
        @SuppressLint("NewApi")
        @Override
        public void run() {

          if (!result.status.equals("1")) {
            Log.v("接口返回状态", "status=" + result.status + "接口返回错误或用户不在范围内");
            hasShowed = false;
            return;
          }

          // Log.v("hasShowed", hasShowed + "");
          // if (hasShowed)
          // return;

          Util.sendNotification(PushService.this);
          // hasShowed = true;
        }