在android中,我试图在预定义的时间访问数据库。在我的应用程序中,它运行一个简单的 android 服务,在其中我想在特定时间检查外部数据库(MySQL)。我正在使用 java web 服务来访问数据库。
public class DBService extends Service {
private static final String SOAP_ACTION = "http://dbconnectivity.com/test/";
private static final String METHOD_NAME = "test";
private static final String NAMESPACE = "http://dbconnectivity.com";
private static final String URL = "http://10.0.2.2:8089/DB_Connectivity/services/SqlConnectivity?wsdl";
String str;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
//Toast.makeText(this, "Test", Toast.LENGTH_LONG).show();
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("time",0);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
SoapPrimitive s = response;
str = s.toString();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(this, "Test "+str, Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service destroyed ...", Toast.LENGTH_LONG).show();
}
}
这个任务怎么做?