2014-10-16 3 views
1

Я настроил gcm pushnotification клиентский ресивер для Android. Сервер получает сообщение об успешности отправки ответа от Google, но сообщение не получает на стороне клиента. Сервер приложений использует gcm_on_rails gem для отправки push-уведомления (gcm_on_rails ссылка: https://github.com/dondeng/gcm_on_rails implemenntation). Я застрял в этом месте в течение нескольких дней, любая помощь будет оценена.не получает pushNotification в android

Это мой файл манифеста:

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

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.CALL_PHONE" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

    <!-- GLYMPSE API - Needed to send Glympses via SMS --> 
    <uses-permission android:name="android.permission.SEND_SMS" /> 

    <!-- GLYMPSE API - Needed to read contacts if using the Recipients editor from the Send Wizard --> 
    <uses-permission android:name="android.permission.READ_CONTACTS" /> 

    <!-- GLYMPSE API - Used to query network connection status before attempting network activity --> 
    <!-- Docs: Allows applications to access information about networks --> 
    <!-- Install: View network connections --> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <!-- GLYMPSE API - Used to create a default user profile (nickname/avatar) --> 
    <!-- Optional but highly recommended --> 
    <!-- Docs: Allows an application to read the user's contacts data. --> 
    <!-- Install: Read your contacts --> 
    <uses-permission android:name="android.permission.READ_CONTACTS" /> 

    <!-- GLYMPSE API - Used to create a default user profile (nickname/avatar) --> 
    <!-- Optional but highly recommended --> 
    <!-- Docs: Allows an application to read the user's personal profile data. --> 
    <!-- Install: Read your own contact card --> 
    <uses-permission android:name="android.permission.READ_PROFILE" /> 

    <uses-permission android:name="android.permission.WAKE_LOCK" /> 


    <permission 
     android:name="com.glympse.android.sendlite.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="com.glympse.android.sendlite.permission.C2D_MESSAGE" /> 

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

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <uses-permission android:name="android.permission.VIBRATE" /> 

    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="19" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/icon" 
     android:theme="@style/AppTheme" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".ChaffeoSplash"    
      android:theme="@android:style/Theme.Translucent.NoTitleBar" 
      android:screenOrientation="portrait" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 

     </activity> 

     <activity 
      android:name="com.glympse.android.login.MainActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:label="@string/app_name" 
      android:screenOrientation="portrait" >    
     </activity> 
     <activity 
      android:name="com.glympse.android.home.Home" 
      android:configChanges="orientation|keyboardHidden" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name="com.glympse.android.acceptrejectrides.ShowMyList" 
      android:configChanges="orientation|keyboardHidden" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".IndividualBookings" 
      android:configChanges="orientation|keyboardHidden" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".NoRidesAccRej" 
      android:configChanges="orientation|keyboardHidden" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name="com.glympse.android.yourrides.YourRides" 
      android:configChanges="orientation|keyboardHidden" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".DetailsActivity" 
      android:configChanges="orientation|keyboardHidden" 
      android:exported="true" 
      android:screenOrientation="portrait" /> 
     <activity 
      android:name=".StartRide" 
      android:configChanges="orientation|keyboardHidden" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".FullscreenActivity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".NoRidesYourRides" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".TabGroupActivity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".TabGroup1Activity" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity android:name=".TabsActivity" > 
     </activity> 
     <activity 
      android:name=".TabsActivity2" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".TabsActivity1" 
      android:screenOrientation="portrait" > 
     </activity> 
     <activity 
      android:name=".GlympseSendLiteDemoActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize" 
      android:screenOrientation="portrait" > 
     </activity> 

     <!-- GLYMPSE API - This is required to make the GlympseSendWizard configurator work. --> 
     <activity 
      android:name="com.glympse.android.kit.send.GlympseSendWizard" 
      android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize" > 
     </activity> 

     <!-- GLYMPSE API - This is required to be notified, when Glympse service is restarted. --> 
     <receiver 
      android:name=".GlympseLiteWrapper$ServiceReceiver" 
      android:exported="false" > 
      <intent-filter> 
       <action android:name="com.glympse.android.hal.service.STARTED" /> 
      </intent-filter> 
     </receiver> 

     <activity 
      android:name=".EndRide" > 
     </activity> 

     <receiver 
      android:name="com.glympse.android.notifications.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="com.glympse.android.sendlite" /> 
      </intent-filter> 
     </receiver> 

     <service android:name="com.glympse.android.notifications.GCMNotificationIntentService" /> 

    </application> 

</manifest> 

Это мой Broadcast приемник:

import android.app.Activity; 
import android.content.ComponentName; 
import android.content.Context; 
import android.content.Intent; 
import android.support.v4.content.WakefulBroadcastReceiver; 
import android.widget.Toast; 

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 


     // Explicitly specify that GcmIntentService will handle the intent. 
     ComponentName comp = new ComponentName(context.getPackageName(), 
       GCMNotificationIntentService.class.getName()); 

     // Start the service, keeping the device awake while it is launching. 
     startWakefulService(context, (intent.setComponent(comp))); 
     setResultCode(Activity.RESULT_OK); 


    } 
} 

Это мой класс GCM обслуживание:

public class GCMNotificationIntentService extends IntentService { 

    public static final int NOTIFICATION_ID = 1; 
    private NotificationManager mNotificationManager; 
    NotificationCompat.Builder builder; 

    public GCMNotificationIntentService() { 
     super("GcmIntentService"); 
    } 

    public static final String TAG = "GCMNotificationIntentService"; 

    @Override 
    protected void onHandleIntent(Intent intent) { 
     Bundle extras = intent.getExtras(); 
     GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); 

     String messageType = gcm.getMessageType(intent); 

     String msg = intent.getStringExtra("message"); 

     System.out.println("###############GCM Message type---> " + messageType); 
     System.out.println("GCM intent.getStringExtra()---> " + msg); 

     if (!extras.isEmpty()) { 

      if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR 
        .equals(messageType)) { 
       sendNotification("Send error: " + extras.toString()); 
      } 
      else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED 
        .equals(messageType)) { 
       sendNotification("Deleted messages on server: " 
         + extras.toString()); 
      } 
      else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE 
        .equals(messageType)) { 

       for (int i = 0; i < 3; i++) { 
        Log.i(TAG, 
          "Working... " + (i + 1) + "/5 @ " 
            + SystemClock.elapsedRealtime()); 
        try { 
         Thread.sleep(5000); 
        } catch (InterruptedException e) { 
        } 

       } 
       Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); 

//    sendNotification(""+extras.get(DriverUtils.MESSAGE_KEY)); 


       sendNotification(""+extras.get("message")); 

       Log.i(TAG, "Received: " + extras.toString()); 
       System.out.println("GCM GCM GCM" + extras.toString()); 

      } 
     } 
     GcmBroadcastReceiver.completeWakefulIntent(intent); 
    } 

    @SuppressLint("NewApi") 
    private void sendNotification(String msg) { 

     System.out.println("MESSAGE : " + msg);    

     // Prepare intent which is triggered if the 
     // notification is selected 
     Intent intent = new Intent(this, ChaffeoSplash.class); 
     PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 

     // Build notification 
     // Actions are just fake 
     Notification noti = new Notification.Builder(this) 
      .setContentTitle("Chaffeo") 
      .setContentText(msg) 
      .setSmallIcon(R.drawable.icon) 
      .setContentIntent(pIntent).build(); 
     noti.flags |= Notification.FLAG_AUTO_CANCEL;// hide the notification after its selected 
     noti.defaults |= Notification.DEFAULT_VIBRATE; 
     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

     // hide the notification after its selected 
     notificationManager.notify(0, noti); 
    } 
} 

Может ли один помочь мне решить эта проблема, спасибо заранее.

ответ

0

Обратите внимание, что в следующем коде:

 // Explicitly specify that GcmIntentService will handle the intent. 
    ComponentName comp = new ComponentName(context.getPackageName(), 
      GCMNotificationIntentService.class.getName()); 

вы говорите, что GCMNotificationIntentService находится в главном корпусе приложения. Однако ваш GCMNotificationIntentService находится в com.glympse.android.notifications, а основной пакет вашего приложения - com.glympse.android.sendlite.

Вы можете исправить это следующим образом:

 // Explicitly specify that GcmIntentService will handle the intent. 
    ComponentName comp = new ComponentName(GCMNotificationIntentService.class.getPackage().getName(), 
      GCMNotificationIntentService.class.getName()); 
+0

спасибо Эран за ответ, но это еще не ПОЛУЧАТЬ никаких уведомлений еще ... – user3231064

Смежные вопросы