使用Php推送通知错误

时间:2015-09-08 07:04:04

标签: php android push-notification

我正在使用PHP进行推送通知。我有一个访问密钥但没有设备注册密钥。

有人告诉我如何获取Android的设备注册ID吗?

我正在使用设备ID 应用,它为我提供了alphnumeric值。如果我使用该值,那么它会给我错误。的 InvalidRegistration

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

1 个答案:

答案 0 :(得分: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();
    }

我假设你知道在哪里粘贴&#34; reg device id&#34;在你的php文件中。