是否可以添加更多“快速响应”,因为android可穿戴式通知默认为?

问题描述

对于Android Wearable Notifications,无需使用RemoteInput setChoices选项执行任何操作,某些(第一个响应选项)将立即显示为展开的Notification View中的小按钮。

所有其他响应选项只能通过操作来实现。

是否可以在展开的视图中直接显示所有答案选择?

public class NotificationPublisher extends broadcastReceiver {

public static int flagCancelCurrent = FLAG_CANCEL_CURRENT;
private static String TAG = "NotificationPublisher";



@SneakyThrows
@Override
public void onReceive(Context context,Intent intent) {

    String CHANNEL_ID = context.getResources().getString(R.string.notiChannelID);

    notificationmanager notificationmanager =
            (notificationmanager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    String received_message = intent.getStringExtra("message");
    int esm_msg_hash = received_message.hashCode();

    // Adding additional infos for esm database
    JSONObject received_message_json = new JSONObject(received_message);


    received_message_json.put("timestamp_question_asked",NotificationSingleton.getInstance().checkHash(esm_msg_hash));
    received_message_json.put("identifier",esm_msg_hash);


    // Preparations for IntentService to callback to handheld
    Intent replyIntent = new Intent(context,NotificationIntentService.class);
    replyIntent.putExtra("original_esm_message",received_message_json.toString());
    replyIntent.putExtra("intent_destination","NotificationIntentService");

    // Received Notification Job from Handheld
    JSONObject jsonMessage = new JSONObject(received_message);



    // Preparing notification content and execution
    Log.d(TAG,"Preparing Notification with ID: " + String.valueOf(esm_msg_hash));
    Log.d(TAG,jsonMessage.toString());
    String esm_question = jsonMessage.getString("question");
    CharSequence[] esm_answers = new CharSequence[]{};
    try {
        JSONArray esm_answers_json = jsonMessage.getJSONArray("answers");
        esm_answers = new CharSequence[esm_answers_json.length()];
        for (int i = 0; i < esm_answers_json.length() ; i++) {
            esm_answers[i] = esm_answers_json.get(i).toString();
        }
    } catch (Exception e){
        ;
    }

    boolean add_answers_allowed = false;
    if (!jsonMessage.getString("add_answers_allowed").equals("allow_nothing")) {
         add_answers_allowed = true;
    }


    PendingIntent directReplyPendingIntent = PendingIntent.getService(context,replyIntent,flagCancelCurrent);
    Bundle extras = new Bundle();
    extras.putBoolean(RemoteInputConstants.EXTRA_disALLOW_EMOJI,true);


    RemoteInput remoteInput = new RemoteInput.Builder(context.getString(R.string.key_result_intent_notification))
            .setLabel("Type..")
            .setChoices(esm_answers)
            .setAllowFreeFormInput(add_answers_allowed)
            .addExtras(extras)
            .build();

    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.icon_reply,"Choices",directReplyPendingIntent)
            .setAllowGeneratedReplies(false)
            .addRemoteInput(remoteInput)
            .build();


    Notification notification = new NotificationCompat.Builder(context,CHANNEL_ID)
            .setAutoCancel(true)
            .setongoing(true)
            .setContentText(esm_question)
            .setSmallIcon(R.drawable.ic_survey)
            .addAction(action)
            .build();

    notificationmanager.notify(esm_msg_hash,notification);
    Log.d(TAG,"Notification was published successfully.");


}

预先感谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...