我正在尝试制作一个Android闹钟应用程序,但我得到了以下错误:
对于MyReceiver类型
,方法getSystemService(String)未定义代码:
public class MyReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent)
{
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context, notification);
r.play();
Toast.makeText(context, "Ud tiene pico y placa hoy", Toast.LENGTH_LONG).show();
Notification n = new NotificationCompat.Builder (context)
.setContentTitle("Pico Y Placa")
.setContentText("Mensaje")
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true).build();
NotificationManager notificationManager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
}
}
如果你能让我知道我在这里做错了什么就会很棒!
感谢
答案 0 :(得分:2)
我找到了解决方案,它是:
NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);