在数据库中插入空值

时间:2013-06-05 11:53:08

标签: android android-asynctask

我正在使用GCM生成注册ID,并且它正在产生价值。但我的问题是我使用soap向asp.net服务器发送数据。它在数据库中存储空值。
我已经尝试了这么多,但不知道是什么问题。我还通过给出regID的固定值来检查,并且它存储了那个时间的数据。
我的代码如下:请给我解决方案。

 private class TheTask extends AsyncTask<String, String, String> {
    @Override
    protected void onPreExecute() {

    }

    @Override
    protected String doInBackground(String... params) {

        GCMRegistrar.checkDevice(getApplicationContext());
        GCMRegistrar.checkManifest(getApplicationContext());

        String regId = GCMRegistrar
                .getRegistrationId(getApplicationContext());

        if (regId.equals("")) {
            flag = 1;
            GCMRegistrar.register(getApplicationContext(), "1507652xxxxx");

        } else {
            Log.v("Registration", "Already registered, regId: " + regId);
        }

        if (flag == 1) {
            regId = GCMRegistrar.getRegistrationId(getApplicationContext());

            request = new SoapObject(NAMESPACE, METHOD_NAME);

            regisid = new PropertyInfo();
            regisid.setName("RegId");
            regisid.setValue(regId);
            regisid.setType(String.class);
            request.addProperty(regisid);

            SoapSerializationEnvelope envp = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envp.dotNet = true;
            envp.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            try {
                androidHttpTransport.call(SOAP_ACTION, envp);
                SoapPrimitive response = (SoapPrimitive) envp.getResponse();
                Response = response.toString();

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        return Response;
    }

    @Override
    protected void onPostExecute(String result) {

    }
}

1 个答案:

答案 0 :(得分:1)

您需要在GCMIntentService的onRegistered回调方法中执行webservice调用。

public class GCMIntentService extends GCMBaseIntentService {

public GCMIntentService() {
    super(SENDER_ID);
}   


@Override
protected void onRegistered(Context arg0, String regId) {
    //Call webservice here

}