Skip to content

Require a SENDER_ID now. #615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Parse/src/main/java/com/parse/GcmRegistrar.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
private static final String REGISTRATION_ID_EXTRA = "registration_id";
private static final String ERROR_EXTRA = "error";

// Client-side key for [email protected]. See parse/config/gcm.yml for server-side key.
private static final String PARSE_SENDER_ID = "1076345567071";
private static final String SENDER_ID_EXTRA = "com.parse.push.gcm_sender_id";

public static final String REGISTER_ACTION = "com.google.android.c2dm.intent.REGISTER";
Expand Down Expand Up @@ -134,24 +132,33 @@ private Task<Void> sendRegistrationRequestAsync() {
// a 32-bit integer. For `android:value="567327206255"`, this returns a truncated integer
// because 567327206255 is larger than the largest 32-bit integer.
Bundle metaData = ManifestInfo.getApplicationMetadata(context);
String senderIDs = PARSE_SENDER_ID;
String senderID = null;

if (metaData != null) {
Object senderIDExtra = metaData.get(SENDER_ID_EXTRA);

if (senderIDExtra != null) {
String senderID = actualSenderIDFromExtra(senderIDExtra);
senderID = actualSenderIDFromExtra(senderIDExtra);

if (senderID != null) {
senderIDs += ("," + senderID);
} else {
if (senderID == null) {
PLog.e(TAG, "Found " + SENDER_ID_EXTRA + " <meta-data> element with value \"" +
senderIDExtra.toString() + "\", but the value is missing the expected \"id:\" " +
"prefix.");
return null;
}
}
}

request = Request.createAndSend(context, senderIDs);
if (senderID == null) {
PLog.e(TAG, "You must provide " + SENDER_ID_EXTRA + " in your AndroidManifest.xml\n" +
"Make sure to prefix with the value with id:\n\n" +
"<meta-data\n" +
" android:name=\"com.parse.push.gcm_sender_id\"\n" +
" android:value=\"id:<YOUR_GCM_SENDER_ID>\" />");
return null;
}

request = Request.createAndSend(context, senderID);
return request.getTask().continueWith(new Continuation<String, Void>() {
@Override
public Void then(Task<String> task) {
Expand Down