GcmService.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. Copyright 2015 Google Inc. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.dev.deben.implementation;
  14. import android.os.Bundle;
  15. import android.os.SystemClock;
  16. import com.google.android.gms.gcm.GcmListenerService;
  17. import org.json.JSONException;
  18. import java.io.IOException;
  19. import java.util.HashMap;
  20. /**
  21. * Service used for receiving GCM messages. When a message is received this service will log it.
  22. */
  23. public class GcmService extends GcmListenerService {
  24. function fn = new function(this);
  25. @Override
  26. public void onMessageReceived(String from, Bundle data) {
  27. System.out.println("Msg from: " + from + ", " + data);
  28. try {
  29. fn.writeSetting("requestId", data.getString("requestId"));
  30. } catch (IOException | JSONException e) {
  31. e.printStackTrace();
  32. }
  33. int id = fn.notifier(from, "New VPN login request");
  34. SystemClock.sleep(30000);
  35. fn.cancelNotify(id);
  36. }
  37. }