android - MyReciever 类型未定义方法 getsystemservice(string)

标签 android eclipse alarm

我正在尝试制作一个 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/

相关文章:

android - Eclipse 找不到 R.layout.simple_list_item_1

android - SlideDateTimePicker 日期时间选择器打开问题

java - 为什么在 Eclipse 中使用 Guava 库时调试不起作用?

java - maven pom.xml 提示执行无法解析依赖关系但功能正常

android - 在android中开发每日闹钟

java - LibGDX 日志记录未显示在 logcat 中

SetContentView 行中的 Android OutOfMemoryError

android - 与 adb 的连接已关闭,并发生严重错误

javascript - Firefox OS 闹钟唤醒关闭的应用程序