简体   繁体   中英

Titanium CloudPush properties on shared_prefs folder

SDK 3.2.1, Android 4.2.2

Hi, I've noticed CloudPush generates this file: /data/data/your.app.id/shared_prefs/com.appcelerator.cloud.push.PushClient.xml

with this content:

<map>
<string name="pushType">GCM</string><int name="pushUnreadNotifMsgCount" value="0"/><int name="GCMUsedAppVersion" value="1"/>
<long name="GCMOnServerExpirationTimeMs" value="0000000000000"/>
<string name="GCMRegistrationId">APA91bFg...mjhY</string>
<string name="GCMSenderId">219575370718</string>
<string name="appKey">A4pTGcJ1...vb7</string>
</map>

I've been caching CloudPush DeviceToken in Ti.App.properties! Can we retrieve this GCMRegistrationId from the above file? It's the CloudPush DeviceToken.

Open this file with Titanium.Filesystem.getFile() and then parse it with Titanium.XML.parseString() .

var filepath = Ti.Filesystem.applicationDataDirectory + 'shared_prefs/com.appcelerator.cloud.push.PushClient.xml';
var pushClientFile = Ti.Filesystem.getFile(filepath);
var pushClientXmlString = pushClientFile.read().toString();

var pushClientXml = Ti.XML.parseString(pushClientXmlString);

var node, registrationId;

for (var i = 0; i < pushClientXml.childNodes.length; i++) {
    node = pushClientXml.childNodes.item(i);
    if (node.getAttribute('name') === 'GCMRegistrationId') {
        registrationId = node.textContent;
        break;
    }
}

alert(registrationId);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM