簡體   English   中英

為什么我不能在通知中添加文本輸入,以及如何設置鍵盤類型?

[英]Why can't I add a text input to my notification and how would I set the keyboard type?

我有一個運行Android 6.0.1版的Samsung Galaxy S6,並且正在按照android開發人員文檔中的示例向我的通知添加內聯回復操作。 但是,這不僅對我不起作用,而且我不確定如何將此嵌入式響應的鍵盤類型更改為numberDecimal。

我看到通知中沒有內聯文本框,而只是在通知的常規內容下方附加了一個普通圖標和相應的標簽。 這是我嘗試過的:

Intent actualAmountIntent = new Intent(context, ActualAmountReceiver.class);
actualAmountIntent.putExtra("expenseId", expense.id);
PendingIntent actualAmountPendingIntent = PendingIntent.getBroadcast(context, 0, actualAmountIntent, 0);
RemoteInput remoteInput = new RemoteInput.Builder(ActualAmountReceiver.ACTUAL_AMOUNT_KEY)
        .setLabel(context.getString(R.string.actual_amount))
        .build();
Notification.Action action =
    new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.add_icon),
        context.getString(R.string.actual_amount), actualAmountPendingIntent)
            .addRemoteInput(remoteInput)
            .build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context)
    .setContentTitle(expense.name)
    .setContentText(context.getString(R.string.scheduled_expense_notification))
    .setAutoCancel(true)
    .setSmallIcon(R.drawable.my_app_icon)
    .addAction(action)
    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
notificationManager.notify((int)expense.id, builder.build());

ActualAmountReceiver.java:

package my.app.package;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class ActualAmountReceiver extends BroadcastReceiver {
    public static final String ACTUAL_AMOUNT_KEY = "actualAmount";

    MyDbHelper dbHelper;

    public void onReceive(Context context, Intent intent) {
        dbHelper = new MyDbHelper(context);
        Expense scheduledExpense = dbHelper.getExpense(intent.getLongExtra("expenseId", -1L));
        Float actualAmount = intent.getFloatExtra(ACTUAL_AMOUNT_KEY, -1.0f);

        System.out.println("actual amount received id(" + scheduledExpense.id + ") " +
                           "name(" + scheduledExpense.name + ") " +
                           "type(" + scheduledExpense.type + ") " +
                           "amount(" + amount + ")");

        dbHelper.close();
    }
}

內聯回復可在Android 7.0牛軋糖上使用。 正如您提到的,您的設備中裝有棉花糖,它將無法正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM