【问题标题】:Sony Smartwatch 2 and push notifications索尼 Smartwatch 2 和推送通知
【发布时间】:2014-03-12 16:22:45
【问题描述】:

我正在尝试将通知+控件示例订阅到 Google Cloud Messaging,以便直接将推送通知接收到手表。

我已添加权限:


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

添加了接收器更新和服务:

    <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>

并使用 link 中的方法实现了 MyReceiver 类

onReceive 方法只是在第一次注册时被调用。它给了我 tokenID,但它既没有收到通知,也没有在我激活示例应用程序时被调用。

我已经使用普通的 Android 应用测试了 Sender Server,它成功发送了通知

关于向智能手表发送推送通知的任何提示?

谢谢!

更新:现在我的问题已向前推进,我已将 MyReceiver.java 更改为:

公共类 MyReceiver 扩展 GCMBroadcastReceiver{

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

}

并且我已经实现了 RemoteNotificationIntentService 类:

公共类 RemoteNotificationIntentService 扩展 GCMBaseIntentService { 公共静态枚举 RemoteNotificationFields{ RN_TITLE、RN_BODY、RN_TICKER、RN_SOUND、RN_SMALL_ICON、RN_LARGE_ICON、RN_LED_COLOR_ARGB }; 私有静态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");
}

}

但它没有在任何方法中输入此方法,我收到此消息:
V/GCMBroadcastReceiver(4052): onReceive: com.google.android.c2dm.intent.RECEIVE
V/GCMBroadcastReceiver(4052):GCM IntentService 类:com.sonymobile.smartconnect.extension.notificationsample.RemoteNotificationIntentService
V/GCMBaseIntentService(1825):获取唤醒锁

更新 2

我终于实现了在我的类中获取数据,我需要将服务添加到清单中

【问题讨论】:

  • 有效!如果有人在此帖子上需要帮助

标签: android push-notification sony sony-smartwatch


【解决方案1】:

在您的普通 Android 应用中,您能否成功接收 C2DM 消息?无论您是创建标准 Android 应用程序还是为 SW2 创建 Control 扩展程序,接收 C2DM 通知应该是相同的。唯一的区别是,对于 SW2,您在收到 C2DM 通知后,将其添加到 SW2 的 Content Provider 以将通知从您的手机推送到手表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    相关资源
    最近更新 更多