2017-07-11 35 views
0

几年前我创建了一个应用程序,但是,我刚刚更新了Android Studios,因此,我的通知代码无法正常工作,因为Android并未在最新的SDK版本中使用此代码我尝试过使用Notification.Builder与我的代码,但是,我收到一个错误,所以有人可以帮助我。无法解析符号(contentIntent)

我收到的错误是cannot Resolve symbol (contentIntent);

String ns = Context.NOTIFICATION_SERVICE; 
mNotificationManager = (NotificationManager) getSystemService(ns); 

Notification.Builder builder = new Notification.Builder(mContext) 
    .setSmallIcon(R.drawable.ic_launcher) 
    .setContentTitle("Fall Detector") 
    .setContentText("Running") 
    .setContentIntent(contentIntent); 
builder.build(); 
Notification notification = builder.getNotification(); 

mNotificationManager.notify(1, notification); 
+0

可能重复[setLatestEventInfo无法解析](https://stackoverflow.com/questions/32450449/setlatesteventinfo-cannot-be-resolved) – Sufian

+0

Sufian请你为我重写我的方法,因为我挣扎着。谢谢 – user8162255

+0

当您尝试Notification.Builder时,您会收到哪些错误? (你写了“一些错误”) –

回答

0

这应该工作:

Notification.Builder builder = new Notification.Builder(mContext); 
builder.setSmallIcon(R.drawable.ic_launcher) 
builder.setContentTitle("Fall Detector") 
builder.setContentText("Running") 
builder.setContentIntent(contentIntent); 
builder.build(); 

Notification notification = builder.getNotification(); 

mNotificationManager.notify(1, notification); 
+0

Greaper这不工作,因为它无法解决(contentIntent); – user8162255

+0

@ user8162255确保contentIntent实例是[PendingIntent](https://developer.android.com/reference/android/app/Notification.Builder.html#setContentIntent(android.app.PendingIntent)) – Greaper

+0

Greaper我改写了代码检查我的问题,但是,它仍然说无法解决(contentIntent); – user8162255

0

哪里是乌尔contentIntent变量?请屏幕截图