2013-08-26 82 views
0

我的應用程序在收到它在Log Cat中顯示的NosuchMethodError(第107行)(即.setWhen(System.currentTimeMillis())。build();在我的文件中,能有人幫助, 我的設備版本爲4.0+和代碼作爲Android通知管理器問題

 final Bundle bundle = intent.getExtras(); 
    final Object systemService = context.getSystemService(Context.NOTIFICATION_SERVICE); 

    // Retrieve notification details from the intent 
    final String tickerText = bundle.getString(TICKER_TEXT); 
    final String message = bundle.getString(MESSAGE); 
    final String notificationTitle = bundle.getString(TITLE); 
    final String notificationSubText = bundle.getString(SUBTITLE); 
    int notificationId = 0; 
    Intent pintent = new Intent(context,MainActivity.class); 
    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, pintent, 0); 

    Notification notification = new Notification.Builder(context) 
           .setContentTitle(notificationTitle) 
           .setContentText(message) 
           .setTicker(tickerText) 
           .setAutoCancel(true) 
           .setSound(Uri.parse("android.resource://"+ context.getPackageName() + "/raw/horn")) 
           .setSmallIcon(R.drawable.ic_launcher) 
           .setContentIntent(contentIntent) 
           .setWhen(System.currentTimeMillis()).build(); 

    NotificationManager notificationMgr = (NotificationManager) systemService; 
    notificationMgr.notify(notificationId, notification); 

回答

0

也許因爲如下setWhen()僅在API層面11.檢查,如果你正在運行在任何低版本的設備項目增加。

如果是這樣,那麼你必須去向後兼容,並嘗試瞭解它。