【发布时间】:2014-10-31 19:40:44
【问题描述】:
大家好,我刚开始使用 Android,我正在尝试从与我的主要活动不同的类发出通知。但是 e.printStackTrace() 说“null”并停在以下行:“NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);”如果我从 mainActivity 发出相同的通知,一切顺利。你能帮我吗?
if(giorni_di_differenza <= 15)
{
try{
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
NotificationCompat.Builder n = new NotificationCompat.Builder(context)
.setContentTitle(nome_evento)
.setContentText(descrizione_evento)
.setContentIntent(pi)
.setAutoCancel(true)
.setLights(Color.GREEN, 1000, 1000)
.setSmallIcon(R.drawable.ic_launcher);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n.build());
}catch(Exception e){
e.printStackTrace();
}
}
如果您需要更多代码,我可以发给您。
LogCat:http://pastebin.com/W4hKbf6W(Pause GC错误是三星库存ROM的错误)
【问题讨论】:
-
好的,一秒钟 @kalyanpvs
标签: android notifications