使用导航抽屉应用程序时的IntentService GCMIntent服务异常

时间:2015-05-21 11:41:04

标签: android android-fragments google-cloud-messaging

我尝试在导航抽屉应用上收到来自PushBots的通知MainActivity和多个片段....我在HomeFragment

中编写了此代码
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {

            View rootView = inflater.inflate(R.layout.fragment_home, container,
                    false);
    diviceReg.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Pushbots.sharedInstance().init(getActivity());

                }
            });
}

这是我的清单文件

 <!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="info.androidhive.slidingmenu.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="info.androidhive.slidingmenu.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive dataf message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity

            android:name="info.androidhive.slidingmenu.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
            <action android:name="info.androidhive.slidingmenu.MESSAGE" />
            <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver
    android:name="com.pushbots.google.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <!-- Receives the actual messages. -->
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <!-- Receives the registration id. -->
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="info.androidhive.slidingmenu" />
    </intent-filter>
</receiver>
<receiver android:name="com.pushbots.push.DefaultPushHandler" />
<service android:name="com.pushbots.push.GCMIntentService" />

    </application>

当我发送通知,应用程序停止并出现以下错误时,我成功在PushBots ... BUT 上注册了我的设备:

05-21 12:14:07.613: E/AndroidRuntime(12087): FATAL EXCEPTION: IntentService[GCMIntentService-1037294394366-1]
05-21 12:14:07.613: E/AndroidRuntime(12087): java.lang.NoClassDefFoundError: android.support.v4.app.NotificationManagerCompat

什么错了?

2 个答案:

答案 0 :(得分:0)

改变说明:

<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver"
          android:permission="com.google.android.c2dm.permission.SEND">

     <intent-filter>
       <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
       <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
       <category android:name="YOUR PACKAGE NAME"/>
     </intent-filter>

</receiver>

答案 1 :(得分:0)

您的项目找不到android.support.v4.app.NotificationCompat。通过SDK Manager下载Android支持库和Android支持存储库,并在您的类中导入NotificationCompat。

作为旁注,我看到您使用第三方库(PushBots)。只是想让您知道他们的示例使用了弃用的材料。您不需要<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>