我试图订阅Google消息传递的notification+control示例,以便直接将推送通知发送到手表。
我还要加上以下内容:
<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>并使用方法实现MyReceiver类,如本链接中所示。
onReceive方法只是在第一次注册时被调用。它给了我tokenID,但是它既没有收到通知,也没有在我激活示例应用程序时调用它。
我已经用一个普通的Android应用程序测试了发件人服务器,它成功地发送了通知
向智能手表发送推送通知有什么提示吗?
谢谢!
UPDATE:现在我的问题已经向前推进了,我已经将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 };
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
我最终实现了获取类中的数据,我需要将服务添加到清单中。
发布于 2014-03-12 17:27:56
在您的正常安卓应用程序中,您能够成功地接收C2DM消息吗?接收C2DM通知应该是相同的,无论您是要为SW2创建一个标准的Android应用程序还是一个控件扩展。唯一的区别是,对于SW2,在您收到C2DM通知之后,您可以将它添加到SW2的内容提供者中,以将通知从您的手机推送到手表。
https://stackoverflow.com/questions/22357739
复制相似问题