2015-09-08 124 views
0

我正在使用PHP進行推送通知。我有一個訪問鍵,但沒有設備註冊碼。使用Php推送通知錯誤

任何一個告訴我如何獲得Android的設備註冊ID?

我正在使用設備Id應用程序它給了我alphnumeric值。如果我使用這個值,那麼它會給我錯誤。 InvalidRegistration

{"multicast_id":8028101205529537543,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]} 
+0

關注此鏈接https://developers.google.com/cloud-messaging/android/client –

回答

1
private void registerInBackground() { 
     new AsyncTask<Void, Void, String>() { 
      @Override 
      protected String doInBackground(Void... params) { 
       String msg = " "; 
       try { 
        if (gcm == null) { 
         gcm = GoogleCloudMessaging.getInstance(Main.this); 
        } 
        regId = gcm.register(Config.GOOGLE_PROJECT_ID); 
        Log.d("RegisterActivity", "registerInBackground - regId: " + regId); 
        msg = "Device registered, registration ID=" + regId; 
        String result= ShareExternalServer.shareRegIdWithAppServer(Main.this,regId); 
        storeRegistrationId(Main.this, regId); 
        Log.i("RegId Sent To Server", result); 
       } catch (IOException ex) { 
        msg = "Error :" + ex.getMessage(); 
        Log.d("RegisterActivity", "Error: " + msg); 
       } 
       Log.d("RegisterActivity", "AsyncTask completed: " + msg); 
       return msg; 
      } 

      @Override 
      protected void onPostExecute(String msg) { 
       Log.d("RegisterActivity", "registerInBackground - regId: "+ regId); //Device Registration Id .. Copy it. 
       Toast.makeText(getApplicationContext(),"Registered with GCM Server." + msg, Toast.LENGTH_LONG).show(); 
      } 
     }.execute(null, null, null); 
    } 
    //This method saves the generated device id in your shred prefrences 
    private void storeRegistrationId(Context context, String regId) { 
     final SharedPreferences prefs = getSharedPreferences(Main.class.getSimpleName(), Context.MODE_PRIVATE); 
     Log.i("Mudit Sen", "Saving regId on app version "); 
     SharedPreferences.Editor editor = prefs.edit(); 
     editor.putString(REG_ID, regId); 
     try { 
      editor.putInt("appVersion", context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode); 
     } catch (PackageManager.NameNotFoundException e) { 
      e.printStackTrace(); 
     } 
     editor.commit(); 
    } 

我假設你知道去哪裏粘貼 「REG設備ID」 在你的PHP文件。