对于MyReciever类型,方法getsystemservice(string)是未定义的

时间:2015-02-22 20:27:31

标签: 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); 


  }

  }

如果你能让我知道我在这里做错了什么就会很棒!

感谢

1 个答案:

答案 0 :(得分:2)

我找到了解决方案,它是:

NotificationManager notificationManager = 
   (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);