我正在尝试制作一个 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);
}
}
如果你能让我知道我在这里做错了什么,那就太好了!
谢谢
最佳答案
我找到了解决方案,它是:
NotificationManager notificationManager =
(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
关于android - MyReciever 类型未定义方法 getsystemservice(string),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28662845/