2011-11-09 52 views
1

當我的應用程序在註冊過程中崩潰時,我嘗試了很多可能的修復方法,但沒有希望。我已經在服務器端使用了PHP。對它的任何幫助,下面是我添加的代碼它。我沒有讓應用程序在C2DM註冊過程中崩潰?

1.In the Main Activity 

C2DMessaging.register(this,「[email protected]」);

2.In的C2DMessaging類

公共靜態無效寄存器(上下文的背景下,字符串senderId) {

意圖registrationIntent =新意圖(REQUEST_REGISTRATION_INTENT);

registrationIntent.setPackage(GSF_PACKAGE); 
    registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,PendingIntent.getBroadcast(context, 0, new Intent(), 0)); 

    registrationIntent.putExtra(EXTRA_SENDER, senderId); 
    context.startService(registrationIntent); 
    // TODO: if intent not found, notification on need to have GSF 
}  

我的清單文件

<?xml version="1.0" encoding="utf-8"?> 

<uses-permission android:name="com.requestec.push.permission.C2D_MESSAGE" />  
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> 

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name="com.notify.AndroidNotification" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <service android:name=".C2DMReceiver" android:enabled="true" /> 
    <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> 
    <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <category android:name="com.kk.push" /> 
     </intent-filter> 
     <!-- Receive registration ids --> 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
      <category android:name="com.kk.push" /> 
     </intent-filter> 

    </receiver> 

</application> 

我不知道我缺少這個我已經嘗試了所有可能的M EANS,還是我在這裏錯過了任何基本的東西。謝謝

+0

您可以包括你得到的錯誤信息(使用DDMS)? –

+0

謝謝你的回覆,我得到了11-10 15:29:50.443:WARN/ActivityManager(59):Permission Denial:receiving Intent {act = com.google.android.c2dm.intent.REGISTRATION cat = [com.kk .push](有額外)} to com.kk.push需要com.kk.push.permission.C2D_MESSAGE由於發件人com.google.android.gsf(uid 10023) – Karthik

+0

而且還有11-10 16:01:07.353: ERROR/C2DMRegistrar(188):[C2DMReg] handleRequest被捕獲java.io.IOException:SSL關閉失敗:系統調用期間發生I/O錯誤,Broken pipe – Karthik

回答

2

看起來像你有權限問題。

假設你的主要活動被稱爲Main.java,你必須(擴展C2DMBaseReceiver,處理的onError和的onMessage)一類C2DMReceiver,你AndroidManifest應該是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.kk.push" android:versionCode="1" 
android:versionName="1.0"> 
<uses-sdk android:minSdkVersion="8" /> 

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

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.INTERNET" /> 

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".Main" android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <receiver android:name=".C2DMReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND"> 
     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION"></action> 
      <category android:name="com.kk.push" /> 
     </intent-filter> 

    </receiver> 

</application> 

相關問題