您好我正在使用索尼sw2开发一个更复杂的应用程序我想在上下文菜单中显示一个图标或另一个图标,具体取决于从推送通知到达的数据,是否有任何方法可以从ExtensionServie更改图标? / p>
现在布局是在RegistrationInformation类中定义的
public ContentValues getSourceRegistrationConfiguration(String extensionSpecificId) {
ContentValues sourceValues = null;
String iconSource1 = ExtensionUtils.getUriString(mContext,
R.drawable.icn_30x30_message_notification);
String iconSource2 = ExtensionUtils.getUriString(mContext,
R.drawable.icn_18x18_message_notification);
String iconBw = ExtensionUtils.getUriString(mContext,
R.drawable.icn_18x18_black_white_message_notification);
String textToSpeech = mContext.getString(R.string.text_to_speech);
sourceValues = new ContentValues();
sourceValues.put(Notification.SourceColumns.ENABLED, true);
sourceValues.put(Notification.SourceColumns.ICON_URI_1, iconSource1);
sourceValues.put(Notification.SourceColumns.ICON_URI_2, iconSource2);
sourceValues.put(Notification.SourceColumns.ICON_URI_BLACK_WHITE, iconBw);
sourceValues.put(Notification.SourceColumns.UPDATE_TIME, System.currentTimeMillis());
sourceValues.put(Notification.SourceColumns.NAME, mContext.getString(R.string.source_name));
sourceValues.put(Notification.SourceColumns.EXTENSION_SPECIFIC_ID, extensionSpecificId);
sourceValues.put(Notification.SourceColumns.PACKAGE_NAME, mContext.getPackageName());
sourceValues.put(Notification.SourceColumns.TEXT_TO_SPEECH, textToSpeech);
sourceValues.put(Notification.SourceColumns.ACTION_1,
mContext.getString(R.string.action_event_1));
sourceValues.put(Notification.SourceColumns.ACTION_2,
mContext.getString(R.string.action_event_2));
sourceValues.put(Notification.SourceColumns.ACTION_3,
mContext.getString(R.string.action_event_3));
System.out.println("DRAWING");
System.out.println("DRAWING");
System.out.println("DRAWING");
System.out.println("DRAWING");
System.out.println("DRAWING");
sourceValues.put(Notification.SourceColumns.ACTION_ICON_1,
ExtensionUtils.getUriString(mContext, R.drawable.actions_1));
sourceValues.put(Notification.SourceColumns.ACTION_ICON_2,
ExtensionUtils.getUriString(mContext, R.drawable.actions_2));
sourceValues.put(Notification.SourceColumns.ACTION_ICON_3,
ExtensionUtils.getUriString(mContext, R.drawable.actions_3));
return sourceValues;
}
有没有办法改变它:
sourceValues.put(Notification.SourceColumns.ACTION_ICON_1,
ExtensionUtils.getUriString(mContext, R.drawable.actions_1));
sourceValues.put(Notification.SourceColumns.ACTION_ICON_2,
ExtensionUtils.getUriString(mContext, R.drawable.actions_2));
sourceValues.put(Notification.SourceColumns.ACTION_ICON_3,
ExtensionUtils.getUriString(mContext, R.drawable.actions_3));
类似于:
public ContentValues getSourceRegistrationConfiguration(
Boolean incident) {
System.out.println("K: register! "+incident.toString());
ContentValues sourceValues = null;
if (incident) {
System.out.println("CASE incident");
String iconSource1 = ExtensionUtils.getUriString(mContext,
R.drawable.icn_30x30_message_notification);
String iconSource2 = ExtensionUtils.getUriString(mContext,
R.drawable.icn_18x18_message_notification);
String iconBw = ExtensionUtils.getUriString(mContext,
R.drawable.icn_18x18_black_white_message_notification);
String textToSpeech = mContext.getString(R.string.text_to_speech);
sourceValues = new ContentValues();
sourceValues.put(Notification.SourceColumns.ENABLED, true);
sourceValues
.put(Notification.SourceColumns.ICON_URI_1, iconSource1);
sourceValues
.put(Notification.SourceColumns.ICON_URI_2, iconSource2);
sourceValues.put(Notification.SourceColumns.ICON_URI_BLACK_WHITE,
iconBw);
sourceValues.put(Notification.SourceColumns.UPDATE_TIME,
System.currentTimeMillis());
sourceValues.put(Notification.SourceColumns.NAME,
mContext.getString(R.string.source_name));
sourceValues.put(Notification.SourceColumns.EXTENSION_SPECIFIC_ID,
SampleExtensionService.EXTENSION_SPECIFIC_ID);
sourceValues.put(Notification.SourceColumns.PACKAGE_NAME,
mContext.getPackageName());
sourceValues.put(Notification.SourceColumns.TEXT_TO_SPEECH,
textToSpeech);
sourceValues.put(Notification.SourceColumns.ACTION_1,
mContext.getString(R.string.action_event_1));
sourceValues.put(Notification.SourceColumns.ACTION_2,
mContext.getString(R.string.action_event_2));
sourceValues.put(Notification.SourceColumns.ACTION_3,
mContext.getString(R.string.action_event_3));
sourceValues
.put(Notification.SourceColumns.ACTION_ICON_1,
ExtensionUtils.getUriString(mContext,
R.drawable.actions_1));
sourceValues
.put(Notification.SourceColumns.ACTION_ICON_2,
ExtensionUtils.getUriString(mContext,
R.drawable.actions_2));
sourceValues
.put(Notification.SourceColumns.ACTION_ICON_3,
ExtensionUtils.getUriString(mContext,
R.drawable.actions_3));
} else {
System.out.println("CASE Contract");
String iconSource1 = ExtensionUtils.getUriString(mContext,
R.drawable.icn_30x30_message_notification);
String iconSource2 = ExtensionUtils.getUriString(mContext,
R.drawable.icn_18x18_message_notification);
String iconBw = ExtensionUtils.getUriString(mContext,
R.drawable.icn_18x18_black_white_message_notification);
String textToSpeech = mContext.getString(R.string.text_to_speech);
sourceValues = new ContentValues();
sourceValues.put(Notification.SourceColumns.ENABLED, true);
sourceValues
.put(Notification.SourceColumns.ICON_URI_1, iconSource1);
sourceValues
.put(Notification.SourceColumns.ICON_URI_2, iconSource2);
sourceValues.put(Notification.SourceColumns.ICON_URI_BLACK_WHITE,
iconBw);
sourceValues.put(Notification.SourceColumns.UPDATE_TIME,
System.currentTimeMillis());
sourceValues.put(Notification.SourceColumns.NAME,
mContext.getString(R.string.source_name));
sourceValues.put(Notification.SourceColumns.EXTENSION_SPECIFIC_ID,
SampleExtensionService.EXTENSION_SPECIFIC_ID);
sourceValues.put(Notification.SourceColumns.PACKAGE_NAME,
mContext.getPackageName());
sourceValues.put(Notification.SourceColumns.TEXT_TO_SPEECH,
textToSpeech);
sourceValues.put(Notification.SourceColumns.ACTION_1,
mContext.getString(R.string.action_event_1));
sourceValues.put(Notification.SourceColumns.ACTION_2,
mContext.getString(R.string.action_event_2));
sourceValues.put(Notification.SourceColumns.ACTION_3,
mContext.getString(R.string.action_event_3));
sourceValues
.put(Notification.SourceColumns.ACTION_ICON_1,
ExtensionUtils.getUriString(mContext,
R.drawable.actions_3));
sourceValues
.put(Notification.SourceColumns.ACTION_ICON_2,
ExtensionUtils.getUriString(mContext,
R.drawable.actions_4));
sourceValues
.put(Notification.SourceColumns.ACTION_ICON_3,
ExtensionUtils.getUriString(mContext,
R.drawable.actions_5));
}
return sourceValues;
}
我认为一旦用户界面被绘制就无法改变它,因为虽然该代码被称为ui永远不会改变,但我错了吗?
答案 0 :(得分:0)
好的,谢谢你的澄清。遗憾的是,动态更改抽屉菜单是不可能的,因为您注意到注册代码仅在安装应用程序时调用一次,并且您只能在此时设置菜单图标和操作。
实现您要做的事情的唯一方法是使用Control API设计自己的通知UI。使用Control API,您可以动态更新菜单。