-4
private void registerBackground(){

           Log.v(TAG,"-----regbackgroud method call---");

     new AsyncTask<Void, Void, String>() {


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

              String msg = "";

                try {
                    if (gcm == null) {
                        gcm = GoogleCloudMessaging.getInstance(context);
                  }
                    regid = gcm.register(SENDER_ID);

                    msg = "Device registered, registration id=" + regid;


                    setRegistrationId(context, regid);


                } catch (IOException ex) {
                    msg = "Error ::" + ex.getMessage();

                }
                return msg;

            }


          @Override
          protected void onPostExecute(String msg) {
              super.onPostExecute(msg);

          }

          @Override
          protected void onPreExecute() {
              super.onPreExecute();

          }
      }.execute(null, null, null);

}

这是我的我的代码在这个
1) 执行的预执行方法和
2) doInbackground() 方法没有执行。
请建议我应该做什么以及 JNI 开启时发生的任何错误...

4

1 回答 1

2

No need to call in background

Try Call this method

public void enableGCM() {

        try {
            GCMRegistrar.checkDevice(this);
            GCMRegistrar.checkManifest(this);
            final String regId = GCMRegistrar.getRegistrationId(this);
            if (regId.equals("")) {
                GCMRegistrar.register(this, SENDER_ID);
            } else {
                Log.v("GCM", "Already registered");
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
于 2013-09-05T11:26:29.103 回答