How to scan a barcode from another Android application via Intents
透過其他的應用程式,使用其內部所提供的功能
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
// "SCAN_MODE" for all unknow code
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
// use this method, can get the response by "onActivityResult( )"
startActivityForResult(intent, 0);
}
};
// receive the result public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) { // this line maybe can marked
if (resultCode == RESULT_OK) { // -1
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) { // 0
// Handle cancel
}
}
}
2011年4月28日 星期四
2011年4月25日 星期一
NMEA資訊
NMEA資訊
// get location service
LocationManager location = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
// set location update settings(time...)
location.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,new LocationListener(){
public void onLocationChanged(Location loc) {}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status,Bundle extras) {}
});
// listen the NMEA information when change
location.addNmeaListener(new NmeaListener() {
public void onNmeaReceived(long timestamp, String nmea) {
msg.append(nmea);
}
});
// get location service
LocationManager location = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
// set location update settings(time...)
location.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,new LocationListener(){
public void onLocationChanged(Location loc) {}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status,Bundle extras) {}
});
// listen the NMEA information when change
location.addNmeaListener(new NmeaListener() {
public void onNmeaReceived(long timestamp, String nmea) {
msg.append(nmea);
}
});
System Settings修改
System Settings修改
// get screen off timeout time
try {
time = Settings.System.getInt(
this.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
// modify timeout time to 15 seconds
Settings.System.putInt(
this.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 15000);
// modify rotation enable, 1: auto rotate on; 0: auto rotate off
Settings.System.putInt(
this.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);
// vibrator control
vb = (Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);
vb.vibrate(1000*1000); // parameter: vibrate time(ms)
vb.cancel(); // stop
// get screen off timeout time
try {
time = Settings.System.getInt(
this.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
// modify timeout time to 15 seconds
Settings.System.putInt(
this.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 15000);
// modify rotation enable, 1: auto rotate on; 0: auto rotate off
Settings.System.putInt(
this.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1);
// vibrator control
vb = (Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);
vb.vibrate(1000*1000); // parameter: vibrate time(ms)
vb.cancel(); // stop
訂閱:
文章 (Atom)