0

当我向我的应用程序发送消息时,我收到以下消息:

    08-12 22:17:12.932: W/GTalkService(475): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.example.databasetest (has extras) }
    08-12 22:17:12.932: W/GTalkService(475): Receiver package not found, unregister application com.example.databasetest sender 

如果我的应用程序在尝试接收某些内容时收到消息,则消息似乎必须发送正常。这是我的清单,省略了任何敏感值:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.databasetest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK"/>

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="17" />
    <uses-feature 
        android:glEsVersion="0x00020000"
        android:required="true"/>
    <permission
          android:name="com.example.databasetest.permission.MAPS_RECEIVE"
          android:protectionLevel="signature"/>
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
    <uses-permission android:name="com.example.databasetest.permission.MAPS_RECEIVE" />
        <permission
          android:name="com.example.databasetest.permission.C2D_MESSAGE"
          android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.databasetest.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <meta-data 
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="value"/>
        <activity
            android:name=".Login"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" 
                  android:label="@string/app_name">

        </activity>

        <receiver android:name="com.example.databasetest.GCMreceiver" android:permission="com.google.android.c2dm.permission.SEND">
          <intent-filter>
             <action android:name="com.google.anroid.c2dm.permission.RECEIVE"/>
             <action android:name="com.google.anroid.c2dm.permission.REGISTRATION"/>
             <category android:name="com.example.databasetest"/> 

          </intent-filter>  

        </receiver>


    </application>

    </manifest>

这是我的文件 GCMreceiver.java 中的接收方法,它似乎在正确的位置。永远不会调用日志。

    @Override
        public void onReceive(Context context, Intent intent)  //receives messages from server
        {
            String action = intent.getAction();
            Log.d("IM", "receive : "+action);
            if(action.equals("com.google.android.c2dm.intent.REGISTRATION"))  //get unique registration id back from server
            {
                String registrationId = intent.getStringExtra("registration_id");
                String error = intent.getStringExtra("error");
                Log.d("IM", "registered: " + registrationId);
                if(error != null && !error.isEmpty())
                {
                    Log.d("IM", "error: " + error);
                }

        }
        else if(action.equals("com.google.android.c2dm.intent.RECEIVE")) //or receive message from server
        {
            Log.d("IM", "im receiving");
            if((connector != null) && (connector.loc != null) ) //make sure a gps location is available
            {

                String name = intent.getStringExtra("username");
                String message = intent.getStringExtra("message");
                double lati = intent.getExtras().getDouble("latitude");
                double longi = intent.getExtras().getDouble("longitude");
                messages.add(new Message(name, message, lati, longi));
                chatAdapter.notifyDataSetChanged();
            }
        }

    }
4

0 回答 0