Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 是否可以再加上一句;“快速反应”;作为安卓可穿戴通知的默认设置?_Android_Notifications_Wear Os - Fatal编程技术网

Android 是否可以再加上一句;“快速反应”;作为安卓可穿戴通知的默认设置?

Android 是否可以再加上一句;“快速反应”;作为安卓可穿戴通知的默认设置?,android,notifications,wear-os,Android,Notifications,Wear Os,对于Android可穿戴通知,无需使用RemoteInput setChoices选项,一些(第一响应选项)会立即显示为扩展通知视图中的小按钮 所有其他响应选项只能通过操作访问 是否可以在展开视图中直接显示所有答案选项 公共类NotificationPublisher扩展了BroadcastReceiver{ public static int flagCancelCurrent=FLAG\u CANCEL\u CURRENT; 私有静态字符串TAG=“NotificationPublisher

对于Android可穿戴通知,无需使用RemoteInput setChoices选项,一些(第一响应选项)会立即显示为扩展通知视图中的小按钮

所有其他响应选项只能通过操作访问

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

公共类NotificationPublisher扩展了BroadcastReceiver{
public static int flagCancelCurrent=FLAG\u CANCEL\u CURRENT;
私有静态字符串TAG=“NotificationPublisher”;
@鬼鬼祟祟
@凌驾
公共void onReceive(上下文、意图){
String CHANNEL_ID=context.getResources().getString(R.String.noticechannelid);
通知经理通知经理=
(NotificationManager)context.getSystemService(context.NOTIFICATION\u服务);
字符串已接收_message=intent.getStringExtra(“消息”);
int esm_msg_hash=已收到消息。hashCode();
//为esm数据库添加其他信息
JSONObject received_message_json=新JSONObject(received_message);
收到消息json.put(“timestamp\u question\u asked”,NotificationSingleton.getInstance().checkHash(esm\u msg\u hash));
收到的消息为json.put(“标识符”,esm消息为哈希);
//准备将IntentService回调到掌上电脑
Intent replyIntent=新意图(上下文,NotificationIntentService.class);
replyIntent.putExtra(“原始esm消息”,收到消息\u json.toString());
回复内容putExtra(“目的地”、“通知目的地服务”);
//从手持设备接收到通知作业
JSONObject jsonMessage=新的JSONObject(收到的消息);
//准备通知内容和执行
Log.d(标记,“准备ID为+String.valueOf(esm_msg_hash)的通知”);
d(标记,jsonMessage.toString());
字符串esm_question=jsonMessage.getString(“问题”);
CharSequence[]esm_answers=新的CharSequence[]{};
试一试{
JSONArray esm_answers_json=jsonMessage.getJSONArray(“answers”);
esm_answers=new CharSequence[esm_answers_json.length()];
for(int i=0;i
提前谢谢

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, 0, 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.");


}