搜尋此網誌

2012年3月19日

GPS on / off toggleing sample code

public void gpsOnOff(Boolean action, int retryFreq, int waitTime) {
                        boolean lastStateIsOn = false;
                        boolean curStateIsOn = false;
                        Thread thread = null;     
                       
                        gpsl = new LocationListener() {
                                @Override
                                public void onLocationChanged(Location arg0) {
                                        // TODO Auto-generated method stub                                 
                                }
                                @Override
                                public void onStatusChanged(String provider, int status,
                                                Bundle extras) {
                                        // TODO Auto-generated method stub                                 
                                }
                                @Override
                                public void onProviderDisabled(String provider) {
                                        // TODO Auto-generated method stub                                 
                                }
                                @Override
                                public void onProviderEnabled(String provider) {
                                        // TODO Auto-generated method stub                                 
                                }
                        };
                       
                        if (action == true)
                                sendUIMsg("Turn On GPS setting ... ");
                        else
                                sendUIMsg("Turn Off GPS setting ... ");

                        try {
                                Log.w(name, "GPSOnOff toggling");
                                locationManager = (LocationManager) context
                                                .getSystemService(Context.LOCATION_SERVICE);
                               
                                /*ClassLoader cl = null;
                                Class<?> secureClass = cl.loadClass("android.provider.Settings$Secure");
                                Method isMethod = secureClass.getMethod("isLocationProviderEnabled",
                                                ContentResolver.class, String.class);
                                Boolean ret = (Boolean) isMethod.invoke(secureClass, context.getContentResolver(), "gps");
                                Log.w(name, "GPSOnOff status: " + ret);*/
                               
                                /*String str = Settings.Secure.getString(context.getContentResolver(),
                                                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
                                Log.v("GPS", str);
                                if (str != null) {
                                        Log.w(name, "GPSOnOff status: " + str.contains("gps"));
                                }
                                else{
                                        Log.w(name, "GPSOnOff status off");
                                }*/
                               
                                try {
                                        lastStateIsOn = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
                                        Log.w(name, "GPSOnOff lastStateIsOn: " + lastStateIsOn);
                                } catch (SecurityException e) {
                                        e.printStackTrace();
                                        Log.w(name, "GPS SecurityException: " + e.toString());
                                } catch (IllegalArgumentException e) {
                                        e.printStackTrace();
                                        Log.w(name, "GPS IllegalArgumentException: " + e.toString());
                                }                                              

                                if ((lastStateIsOn && action) || (!lastStateIsOn && !action)) {
                                        Log.w(name, "GPSOnOff same setting");
                                        if (curStateIsOn == true) {
                                                Looper.prepare();
                                                locationManager.requestLocationUpdates(
                                                                LocationManager.GPS_PROVIDER, 0, 0, gpsl);
                                                // Looper.loop();
                                                SystemClock.sleep(3000);
                                                locationManager.removeUpdates(gpsl);
                                        }
                                        return;
                                } else {
                                        Settings.Secure.setLocationProviderEnabled(
                                                        context.getContentResolver(),
                                                        LocationManager.GPS_PROVIDER, action);
                                        Log.w(name, "GPSOnOff setting changed");

                                        int retry = 0;
                                        do {
                                                curStateIsOn = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
                                                Log.w(name, "GPSOnOff curStateIsOn: " + curStateIsOn);

                                                if (lastStateIsOn != curStateIsOn)
                                                        break;

                                                SystemClock.sleep(waitTime);
                                                retry++;
                                        } while (retry < retryFreq);
                                       
                                        // curStateIsOn = true;
                                       
                                        if (curStateIsOn == true) {
                                                Looper.prepare();
                                                locationManager.requestLocationUpdates(
                                                                LocationManager.GPS_PROVIDER, 0, 0, gpsl);
                                                // Looper.loop();
                                                SystemClock.sleep(3000);
                                                locationManager.removeUpdates(gpsl);
                                        }
                                }
                        } catch (Exception e) {
                                e.printStackTrace();
                                Log.w(name, "Handler exception: " + e.toString());
                        }
                }      

2012年3月9日

[轉] INSTALL ORACLE JAVA (JDK) 7 IN UBUNTU VIA PPA REPOSITORY

[轉] Installation of Ubuntu Linux 11.10 (Oneiric Ocelot)

Wubi.exe cannot install Ubuntu on Win7 32bit laptop

1.      Get Ubuntu 32bit ISO, extract wubi.exe from the ISO file.
2.      Put wubi.exe and ISO at the same folder.
3.      Run wubi.exe, and it will not download amd64 source file and install on 32bit from the ISO file.
4.      If Win7 use dynamic storage setting, then you cannot install Ubuntu by wubi.exe

[轉] 多重wubi安裝分享 [論壇 - Ubuntu安裝問題]

[轉] 在Excel中依特定欄位的值決定整列的背景色