shared_prefs文件夹上的Titanium CloudPush属性

时间:2014-05-27 19:46:04

标签: android properties titanium cloud

SDK 3.2.1,Android 4.2.2

您好, 我注意到CloudPush生成了这个文件:/data/data/your.app.id/shared_prefs/com.appcelerator.cloud.push.PushClient.xml

有了这个内容:

<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>

我一直在Ti.App.properties中缓存CloudPush DeviceToken! 我们可以从上面的文件中检索此GCMRegistrationId吗? 它是CloudPush DeviceToken。

1 个答案:

答案 0 :(得分:0)

使用Titanium.Filesystem.getFile()打开此文件,然后使用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);