Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.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_Fragment - Fatal编程技术网

如何在android中的片段中创建通知

如何在android中的片段中创建通知,android,notifications,fragment,Android,Notifications,Fragment,我正在尝试在片段中创建通知。我有错误。能帮忙吗 这是我的密码 NotificationManager notification = (Notification) getSystemService(getActivity().NOTIFICATION_SERVICE); int icon = R.drawable.ic_launcher; CharSequence tickerText = "your daily tip"; long when System.currentTimeMillis()

我正在尝试在片段中创建通知。我有错误。能帮忙吗

这是我的密码

NotificationManager notification = (Notification) getSystemService(getActivity().NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "your daily tip";
long when System.currentTimeMillis();
Context context = getActivity();
CharSequence contentTitle = "AutoKit";
CharSequence = contentText = "hi";
Intent notificationIntent = new Intent();
PendingIntent contentIntent = PendingIntent.getActivity(getActivity(), 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contextTitle, contentText, contentIntent);
notificationManager.notify(1, notification);

错误在第一行。

用这一行更改您的第一行,应该做到以下几点:

NotificationManager notification = ( NotificationManager ) getActivity().getSystemService( getActivity().NOTIFICATION_SERVICE );

用这一行更改您的第一行,应该做到以下几点:

NotificationManager notification = ( NotificationManager ) getActivity().getSystemService( getActivity().NOTIFICATION_SERVICE );

您正在尝试将
通知管理器
强制转换为
通知
。您正在尝试将
通知管理器
强制转换为
通知