微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决是否可以添加更多“快速响应”,因为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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?