首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >索尼智能手表2和推送通知

索尼智能手表2和推送通知
EN

Stack Overflow用户
提问于 2014-03-12 16:22:45
回答 1查看 565关注 0票数 0

我试图订阅Google消息传递的notification+control示例,以便直接将推送通知发送到手表。

我还要加上以下内容:

代码语言:javascript
复制
<permission android:name="com.example.myapp.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.sonymobile.smartconnect.extension.notificationsample.permission.C2D_MESSAGE" />

添加了接收方、更新和服务:

代码语言:javascript
复制
    <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>

并使用方法实现MyReceiver类,如本链接中所示。

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

我已经用一个普通的Android应用程序测试了发件人服务器,它成功地发送了通知

向智能手表发送推送通知有什么提示吗?

谢谢!

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

公共类MyReceiver扩展GCMBroadcastReceiver{

代码语言:javascript
复制
@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 };

代码语言:javascript
复制
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/4052广播收发器(4052):onReceive: com.google.android.c2dm.intent.RECEIVE

V/ GCM广播收发器(4052):GCM IntentService类: com.sonymobile.smartconnect.extension.notificationsample.RemoteNotificationIntentService

V/GCMBaseIntentService(1825):获得觉醒

更新2

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

EN

回答 1

Stack Overflow用户

发布于 2014-03-12 17:27:56

在您的正常安卓应用程序中,您能够成功地接收C2DM消息吗?接收C2DM通知应该是相同的,无论您是要为SW2创建一个标准的Android应用程序还是一个控件扩展。唯一的区别是,对于SW2,在您收到C2DM通知之后,您可以将它添加到SW2的内容提供者中,以将通知从您的手机推送到手表。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22357739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档