Exemplo n.º 1
0
 public static void watchNetwork() {
   if (m_instance.networkReceiver == null) {
     Log.d(TAG, "install network receiver");
     m_instance.networkReceiver =
         new BroadcastReceiver() {
           @Override
           public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
             if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
               ConnectivityManager mgr =
                   (ConnectivityManager) m_instance.getSystemService(Context.CONNECTIVITY_SERVICE);
               NetworkInfo networkInfo = mgr.getActiveNetworkInfo();
               if (networkInfo != null && networkInfo.isAvailable()) {
                 Log.d(TAG, "network connected!");
                 QWeatherNative.OnNetworkStateChanged(1);
               } else {
                 QWeatherNative.OnNetworkStateChanged(0);
               }
             }
           }
         };
     IntentFilter intentFilter = new IntentFilter();
     intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
     m_instance.registerReceiver(m_instance.networkReceiver, intentFilter);
   }
 }
Exemplo n.º 2
0
 public static void getLocation() {
   Log.d(TAG, "getLocation");
   if (m_instance.m_lm == null)
     m_instance.m_lm = (LocationManager) m_instance.getSystemService(Context.LOCATION_SERVICE);
   if (m_instance.m_lm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) {
     m_instance.m_handler.sendMessage(m_handler.obtainMessage(2));
   } else {
     // open gps
     Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
     m_instance.startActivityForResult(intent, GET_LOCATION_REQUEST_CODE);
   }
 }
Exemplo n.º 3
0
 @Override
 public void handleMessage(Message msg) {
   switch (msg.what) {
     case 2:
       m_instance.doGetLocation();
       break;
   }
   ;
 }
Exemplo n.º 4
0
 public static int networkState() {
   ConnectivityManager mgr =
       (ConnectivityManager) m_instance.getSystemService(Context.CONNECTIVITY_SERVICE);
   NetworkInfo networkInfo = mgr.getActiveNetworkInfo();
   return (networkInfo != null && networkInfo.isAvailable()) ? 1 : 0;
 }
Exemplo n.º 5
0
 public static void launchActivity(String action) {
   m_instance.startActivity(new Intent(action));
 }