gpt4 book ai didi

android - 如何设置报警信息?

转载 作者:行者123 更新时间:2023-11-30 04:10:13 27 4
gpt4 key购买 nike

In alarm app, user gives input String for alarm message and sets alaram. I am able to set and listen alarm.but how to display message set by user? have set many times to set alarm, how can i display respective message for that specific alarm

最佳答案

您的 BroadcastReceiver 中应该有一个 onReceive(Context context, Intent intent) 函数。它看起来像:

public void onReceive(Context context, Intent intent) {   
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, ""); // Second argument is an arbitrary String tag
wl.acquire();

// Put YOUR code here (between WaitLocks)
String userInputtedString = intent.getBundleExtra("UserText")
Toast.makeText(context, userInputtedString, Toast.LENGTH_LONG).show();

wl.release();
}

为了获得该 Bundle,您必须在创建警报时额外传递一个 intent

Intent intent = new Intent(context, AlarmNotification.class);
intent.putExtra("UserText", userInputedString);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);

我刚刚展示了一个 Toast 消息示例,但您也可以将其更改为 Notification 或 AlertDialog。如果这有帮助,请告诉我。

关于android - 如何设置报警信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10978367/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com