推送通知证书问题

时间:2013-11-27 09:25:04

标签: android push-notification

我正在从Stackmob开发推送通知,但通知未发送到移动设备。

当我在控制台中看到它然后显示查询为true,而令牌也能够生成。

从Stackmob开发推送通知是否有任何证书问题?

公共类PushDemoActivity扩展了Activity {

public static String SENDER_ID = "552151775896";
private StackMobUser user;
private static final String TAG = PushDemoActivity.class.getCanonicalName();
private final StackMobCallback standardToastCallback = new StackMobCallback() {
    @Override public void success(String responseBody) {
        threadAgnosticToast(PushDemoActivity.this, "response: " + responseBody, Toast.LENGTH_SHORT);
        Log.i(TAG, "request succeeded with " + responseBody);
    }
    @Override public void failure(StackMobException e) {
        threadAgnosticToast(PushDemoActivity.this, "error: " + e.getMessage(), Toast.LENGTH_SHORT);
        Log.i(TAG, "request had exception " + e.getMessage());
    }
};

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    StackMobAndroid.init(this.getApplicationContext(), StackMob.OAuthVersion.One, 0, "da444511-860e-4b84-ac31-164bb349bd8f", "47e302a3-dd88-4323-8d20-cafe9e6ed7a8");

    // Register for GCM Push
    try {
        GCMRegistrar.checkDevice(this);
        GCMRegistrar.checkManifest(this);
        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
            registerForPush();
        } else {
            Log.v(TAG, "Already registered");
        }
    } catch(UnsupportedOperationException e) {
        Log.w(TAG, "This device doesn't support gcm. Push will not work");
    } 
}

public void loginClick(View v) {
    user.login(standardToastCallback);
}

public void createUserClick(View v) {
    user = new User(getUsername(), getPassword());
    user.save();
}

public void registerRegTokenClick(View w) {
    try {
        user.registerForPush(new StackMobPushToken(getRegistrationIDHolder().getID()), standardToastCallback);
    }
    catch(  Exception e) {
        threadAgnosticToast(PushDemoActivity.this, "no registration ID currently stored", Toast.LENGTH_SHORT);
    }

}

public void sendPushClick(View w) {
    final Map<String, String> payload = new HashMap<String, String>();
    payload.put("payload", getPushPayload());
    user.sendPush(payload, standardToastCallback);
}

public void getRegTokenClick(View w) {
    try {
        threadAgnosticToast(PushDemoActivity.this, getRegistrationIDHolder().getID(), Toast.LENGTH_SHORT);
    }
    catch(PushRegistrationIDHolder.NoStoredRegistrationIDException e) {
        threadAgnosticToast(PushDemoActivity.this, "no registration ID currently stored", Toast.LENGTH_SHORT);
    }
}

public void forceGetRegTokenClick(View w) {
    registerForPush();
    threadAgnosticToast(PushDemoActivity.this, "sent intent to get reg ID", Toast.LENGTH_SHORT);
}

private PushRegistrationIDHolder getRegistrationIDHolder() {
    return new PushRegistrationIDHolder(PushDemoActivity.this);
}

private void registerForPush() {
    GCMRegistrar.register(this, SENDER_ID);
}

private EditText getUsernameField() {
    return (EditText)findViewById(R.id.username);
}

private EditText getPasswordField() {
    return (EditText)findViewById(R.id.password);
}

private String getUsername() {
    return getUsernameField().getText().toString();
}

private String getPassword() {
    return getPasswordField().getText().toString();
}

private EditText getPushPayloadField() {
    return (EditText)findViewById(R.id.token_username);
}

private String getPushPayload() {
    return getPushPayloadField().getText().toString();
}

private void threadAgnosticToast(final Context ctx, final String txt, final int duration) {
    runOnUiThread(new Runnable() {
        @Override public void run() {
            Toast.makeText(ctx, txt, duration).show();
        }
    });
}

0 个答案:

没有答案