gpt4 book ai didi

android - Intent 新 Activity

转载 作者:行者123 更新时间:2023-11-30 03:52:53 25 4
gpt4 key购买 nike

抱歉提出愚蠢的问题...我尝试在 AlarmManager 类上集成一个通知栏(相同的代码在新 Activity 中完美运行)。

Context context = getApplicationContext(); and
Intent notificationIntent = new Intent(this, AlarmManager.class);

这不正确吗?

    public class AlarmReceiver extends BroadcastReceiver {

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager;

@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();



mNotificationManager = (NotificationManager) context.getSystemService(ns);
int icon = android.R.drawable.stat_notify_chat;
CharSequence tickerText = "tickerText";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);

Context context = getApplicationContext();
CharSequence contentTitle = "Title";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(this, AlarmManager.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

mNotificationManager.notify(NOTIFICATION_ID, notification);

最佳答案

您需要调用 context.getSystemService(ns),其中 context 是传递给 onCreate 的变量。

关于android - Intent 新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13882150/

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