我是 android 新手,我在实现推送通知时遇到问题。
正如我阅读的教程中所述,我在 c2dm 中注册并获得了 Auth 令牌,然后在 UrbanAirShip 中注册,使用包 xxxx,获得了应用程序密钥和秘密。
我的项目团队最初使用 API 2.1,当时我通过氦气传输在设备和模拟器中获得了 AppId。
然后我们将API更改为2.2,当时我再次使用另一个发件人ID在c2dm中注册,获得了Auth token,并再次使用新帐户在UrbanAirShip中注册,获得了密钥和秘密。
对于通过 c2dm 传输的前几次尝试,我得到了 AppId,然后在设备和模拟器中我只得到了 null,错误如下所示,
我不知道出了什么问题,无论是 API 级别的更改,还是 c2dm 中的多个发件人 id 注册,或者 UrbanAirShip 中的多个注册相同的包名或卸载次数太多。我已添加 Manifest 文件和 Application 的 oncreate 方法,请指导我取回 AppId。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xxxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
<uses-permission android:name="com.android.vending.BILLING" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<!-- REQUIRED for C2DM -->
<!-- Only this application can receive the messages and registration result -->
<permission android:name="xxxx" android:protectionLevel="signature" />
<uses-permission android:name="xxxx.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive message -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true" />
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="10" />
<application
android:icon="@drawable/logo"
android:label="@string/app_name"
android:name="xx"
android:debuggable="true"
android:allowClearUserData="true"
android:enabled="true" >
<activity
android:label="@string/app_name"
android:name=".activities.SplashActivity"
android:screenOrientation="portrait" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
....
<!-- REQUIRED -->
<receiver android:name="com.urbanairship.CoreReceiver">
<!-- REQUIRED IntentFilter - For Helium and Hybrid -->
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
<!-- REQUIRED for C2DM and Hybrid -->
<receiver android:name="com.urbanairship.push.c2dm.C2DMPushReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actual message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="xxxx" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="xxxx" />
</intent-filter>
</receiver>
<!-- REQUIRED -->
<!-- The 'android:process' parameter is optional. Set it to a value starting
with a colon (:) to make it run in a separate,
private process -->
<service android:name="com.urbanairship.push.PushService"
android:process=":com.urbanairship.push.process"/>
<!-- OPTIONAL, if you want to receive push, push opened and registration completed intents -->
<receiver android:name="xxx.push_notifications.IntentReceiver" />
<service android:name="xxx.inapp.BillingService" />
<receiver android:name="xxx.inapp.BillingReceiver" >
<intent-filter >
<action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
<action android:name="com.android.vending.billing.RESPONSE_CODE" />
<action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>