0

Im trying to subscribe the notification+control sample to Google Cloud Messaging in order to recieve push notification directly to the watch.

i have add the permisions:


<permission android:name="com.example.myapp.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.sonymobile.smartconnect.extension.notificationsample.permission.C2D_MESSAGE" />

Added the receiver update and service:

    <receiver android:name=".MyReceiver"
        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="com.sonymobile.smartconnect.extension.notificationsample" />
      </intent-filter>
      <!-- Receive the registration id -->
      <intent-filter>
          <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
          <category android:name="com.sonymobile.smartconnect.extension.notificationsample" />
      </intent-filter>
  </receiver>

And implemented the MyReceiver class with methods as in this link

The onReceive method is just called the first time it register. It gives me back the tokenID but neither it recieve the notification nor is called when I activate the sample app.

I've tested the Sender Server with a normal Android app and it sends the notification succesfully

Any hint on sending push notifications to the smartwatch?

Thx!

UPDATE:Now i have move forward in my issue, I've changed the MyReceiver.java to:

public class MyReceiver extends GCMBroadcastReceiver{

@Override
protected String getGCMIntentServiceClassName(Context context)
{
    return RemoteNotificationIntentService.class.getName();
}

}

And I have implemented the RemoteNotificationIntentService class:

public class RemoteNotificationIntentService extends GCMBaseIntentService { public static enum RemoteNotificationFields{ RN_TITLE, RN_BODY, RN_TICKER, RN_SOUND, RN_SMALL_ICON, RN_LARGE_ICON, RN_LED_COLOR_ARGB }; private static HashMap FIELD_MAP;

private static final String APPLICATION_NAME = "Appverse Bank 4 Sw2";


public RemoteNotificationIntentService(String senderId) {
    super(senderId);
    System.out.println("init");
    // TODO Auto-generated constructor stub
}

public RemoteNotificationIntentService() {
    super("PUSH_NOTIFICATION_SERVICE");
    // TODO Auto-generated constructor stub
    System.out.println("init");
}

private HashMap<String, String> storeIntentExtras(Context context, Intent intent) {
    try{

        HashMap<String, String> returnValue = new HashMap<String, String>();
        HashMap<String, String> JSONSerializable = new HashMap<String, String>();

        for(String sFieldName:intent.getExtras().keySet()){
            if(FIELD_MAP.containsKey(sFieldName)){
                String sFieldType = FIELD_MAP.get(sFieldName);
                returnValue.put(sFieldType, intent.getStringExtra(sFieldName));
                JSONSerializable.put(sFieldType, intent.getStringExtra(sFieldName));
            }else{
                JSONSerializable.put(sFieldName, intent.getStringExtra(sFieldName));
            }
        }
        //fill mandatory fields
        if(!returnValue.containsKey(RemoteNotificationFields.RN_TITLE.toString())||returnValue.get(RemoteNotificationFields.RN_TITLE.toString()).trim().equals("")){returnValue.put(RemoteNotificationFields.RN_TITLE.toString(), APPLICATION_NAME);}
        if(!returnValue.containsKey(RemoteNotificationFields.RN_TICKER.toString())||returnValue.get(RemoteNotificationFields.RN_TICKER.toString()).trim().equals("")){returnValue.put(RemoteNotificationFields.RN_TICKER.toString(), returnValue.get(RemoteNotificationFields.RN_TITLE.toString()));}
        if(!returnValue.containsKey(RemoteNotificationFields.RN_SMALL_ICON.toString())||returnValue.get(RemoteNotificationFields.RN_SMALL_ICON.toString()).trim().equals("")){returnValue.put(RemoteNotificationFields.RN_SMALL_ICON.toString(), "icon");}
        if(!returnValue.containsKey(RemoteNotificationFields.RN_LED_COLOR_ARGB.toString())||returnValue.get(RemoteNotificationFields.RN_LED_COLOR_ARGB.toString()).trim().equals("")){returnValue.put(RemoteNotificationFields.RN_LED_COLOR_ARGB.toString(), String.valueOf(Color.BLUE));}

        JSONSerializable = null;
        return returnValue;
    }catch(Exception ex){}
    return null;
}

@Override
protected void onMessage(Context context, Intent intent) {
    try{
        System.out.println("message!!!");
    }catch(Exception ex){/*CANNOT LOG CAUSE CALLING LOGGER WILL PROMPT NULL POINTER EXCEPTION*/}        
}

@Override
protected void onRegistered(Context context, String registrationId) {
    try{
        System.out.println("Register K");
    }catch(Exception ex){
        System.out.println("onRegistered "+ex.getMessage());
    }
}

@Override
protected void onUnregistered(Context context, String registrationId) {
    try{
        System.out.println("Unregister K");

    } catch(Exception ex){
        System.out.println("onUnregistered "+ex.getMessage());
    }
}

@Override
protected void onError(Context context, String error) {
    System.out.println("error");
}

}

but it doesnt enter in any method this method and i get this message:
V/GCMBroadcastReceiver(4052): onReceive: com.google.android.c2dm.intent.RECEIVE
V/GCMBroadcastReceiver(4052): GCM IntentService class: com.sonymobile.smartconnect.extension.notificationsample.RemoteNotificationIntentService
V/GCMBaseIntentService(1825): Acquiring wakelock

UPDATE 2

I finnally achieve to get the data in my class, I need to add the service to the manifest

Kechis
  • 5
  • 3

1 Answers1

0

In your normal Android app are you able to receive the C2DM messages successfully? Receiving C2DM notifications should be the same whether you are creating a standard Android app or a Control extension for SW2. The only difference is that for the SW2 after you receive the C2DM notification you then add it to the Content Provider for SW2 to push the notification from your phone to the watch.

mldeveloper
  • 2,253
  • 1
  • 13
  • 14