1

我正在Pushwoosh为需要deviceToken的推送通知集成 API 。我如何得到它:

我使用这个得到空字符串:

String deviceToken=GCMRegistrar.getRegistrationId(getApplicationContext()); 

这些是我在AndroidMainfest.xml中的权限:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

<application ...>
    <receiver
        android:name=".GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.example.gcm" />
        </intent-filter>
    </receiver>
    <service android:name=".GcmIntentService" />
</application>

这是获取deviceToken的正确方法吗?

4

2 回答 2

0

试试下面的代码,希望对你有帮助

    GCMRegistrar.checkDevice(getApplicationContext());
    GCMRegistrar.checkManifest(getApplicationContext());    

    final String regId = GCMRegistrar.getRegistrationId(this);
于 2015-04-03T14:09:44.537 回答
0

您的代码看起来不错,只需将您的 AndroidManifest 与下面的代码进行比较,以确保您没有遗漏任何内容 -

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />

<application ...>
    <receiver
        android:name=".GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.example.gcm" />
        </intent-filter>
    </receiver>
    <service android:name=".GcmIntentService" />
</application>

希望这可以帮助 :)

于 2015-04-03T13:49:33.030 回答