我想保持我的应用程序在后台运行
我有一个应用程序将用户的位置发送到我们的服务器
我有以下代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager;
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria, true);
updateWithNewLocation(null);
locationManager.requestLocationUpdates(provider, (10*60*1000), 10,
locationListener);
}
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location);
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null);
}
public void onProviderEnabled(String provider){ }
public void onStatusChanged(String provider, int status,
Bundle extras){ }
};
public void updateWithNewLocation(Location location) …Run Code Online (Sandbox Code Playgroud) 嗨,我的代码有问题.我的代码是
progressD = ProgressDialog.show(MenuUtama.this, "", "Uploading files to server.....", false);
Thread thread = new Thread(new Runnable(){
public void run(){
//doFileUpload();
try {
// setiap parameter yang akan dikirim melalui http
// harus encode agar
// dapat terbaca dengan baik oleh server
Cursor c = helper.getAll1(almagId);
Cursor cr = helper.getUpImage(almagId);
if(c.moveToFirst()){
//progressD = ProgressDialog.show(context, title, message)
do{
String kdstore = URLEncoder.encode(helper.getKdStore(c).toString(), "utf-8");
String nama = URLEncoder.encode(helper.getNama(c).toString(), "utf-8");
String alamat = URLEncoder.encode(helper.getAlamat(c).toString(), "utf-8");
String kdpos = URLEncoder.encode(helper.getKdPos(c).toString(), "utf-8");
String notelp = URLEncoder.encode(helper.getNotel(c).toString(), …Run Code Online (Sandbox Code Playgroud) 我想要
像这样请求web服务我的参数
urlString = http://ip/autodownload/andro.php?key=apps.apk|2|bla.bla.bla
public void getRequest(String Url) {
Toast.makeText(this, "Tambah Data " + Url + " ", Toast.LENGTH_SHORT).show();
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(urlString);
try {
System.out.println("tes");
HttpResponse response = client.execute(request);
Toast.makeText(this,request(response),Toast.LENGTH_SHORT).show();
String res = EntityUtils.toString(response.getEntity());
System.out.println(res);
Update(res);
} catch (Exception ex) {
Toast.makeText(this, "Gagal Konek Server !", Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我在浏览器中运行它没关系,但是当我在android中运行它是这样的错误
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): FATAL EXCEPTION: main
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): java.lang.IllegalArgumentException: Illegal character in query at index 67: http://10.234.152.120/autodownload/andro.php?key=DeliverReceipt.apk|2|com.sat.deliver
10-25 10:24:49.862: ERROR/AndroidRuntime(14602): at …Run Code Online (Sandbox Code Playgroud) 我有数据库中的数据与复选框中的值
我尝试设置复选框与数据库中的值,如果数据库非空复选框复选框但如果没有选中空复选框..
我的代码如下:
public void load(){
final Cursor c = helper.getSat(almagId);
c.moveToFirst();
if(c.getString(3) != null){
ch1.isChecked();
}
isi2.setText(c.getString(4));
if(c.getString(4) != null){
ch2.isChecked();
}
isi3.setText(c.getString(5));
if(c.getString(5) != null){
ch3.isChecked();
}
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用..我可以解决这个问题吗?谢谢你的反馈:)