Hi all,
I'm trying to implement push notification in an android application which is connected to SMP 3.0 SP03 server. I've followed documents available for enabling push notification on SMP. I've successfully registered the device on the GCM server, and have configured SMP with the API key and sender id to enable Android Push notification in it.
I've successfully registered the device on the SMP server. But when I try to register the device for push notification using following code:
https://{ mobile platform URL }/odata/applications/{latest|v1}/{appid}/Connections('{APPCID}') Method : PUT
Header : "Content-Type" = "application/atom+xml"
"X-HTTP-METHOD" = "MERGE" "X-SUP-APPCID" = {APPCID}
<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"> <content type="application/xml">
<m:properties>
<d: AndroidGcmRegistrationId>{GCM registration ID}</d:
AndroidGcmRegistrationId > </m:properties> </content> </entry> I get error from SMP saying, "HTTP 401 Unauthorized", although I'm providing same login credentials which I've used to register the application on SMP.
Kindly help.
Regards,
Serveshwar Mishra
Request clarification before answering.
Thanks Jitendra and Ali.
Finally the problem was solved.
Error was in the Content-type,
Instead of using "application/atom+xml" it should be "application/xml"
Regards,
Serveshwar Mishra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this:
Request Type: PUT
Do it as a post
<?xml version="1.0"encoding="utf-8"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<content type="application/xml">
<m:properties>
<d:DeviceType>Android</d:DeviceType>
<d:AndroidGcmPushEnabled m:type="Edm.Boolean">true</d:AndroidGcmPushEnabled>
<d:AndroidGcmRegistrationId>Paste your GCM registration ID here
</d:AndroidGcmRegistrationId>
</m:properties>
</content>
</entry>
See if that works for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But when I try to register the device for push notification using following code:
You have to use PUT method in the URL, along with the GCM registration id. Have you got GCM registration id?
Check Registering the Android Client for more info.
Regards,
JK
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jitendra,
Yes I've got the registrationId from GCM and am also using PUT method but still getting the same error. Following is the code:
ConnectivitySettings connectivitySettings = ConnectivitySettings.getInstance();
String queryString = "http://" + connectivitySettings.getSUPHost()
+ ":" + connectivitySettings.getSUPPort()
+ "/odata/applications/latest/"
+ connectivitySettings.getSUPAppID() + "/Connections('"
+ mSMPAppConnectionID + "')";
String GCMRegistrationId =this.restManager.getAppPersistenceManager().getGCMRegistrationId();
IODataEntry entry = new ODataEntry();
entry.putPropertyValue("AndroidGcmRegistrationId", GCMRegistrationId);
String xmlSring = entry.toXMLString();
IRequest request = new BaseRequest();
request.setListener(listener);
request.setPriority(IRequest.PRIORITY_HIGH);
request.setRequestMethod(IRequest.REQUEST_METHOD_PUT);
request.setRequestTAG(requestTag);
request.setRequestUrl(queryString);
request.setData(xmlSring.getBytes());
Map<String,String> headers = new HashMap<String,String>();
headers.put("content-type","application/atom+xml");
headers.put("X-SUP-APPCID", mSMPAppConnectionID);
headers.put("X-HTTP-METHOD", "MERGE");
request.setHeaders(headers);
http://scn.sap.com/people/serveshwar.mishra
Can you check PUT operation in REST client first as i shared the screenshot in above comment?
Regards,
JK
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.