我写了一个代码,在Beacon范围内有弹出通知.
我的通知代码如下:
private void showNotification(String message){
Log.d("Hay8","DCM8");
Intent intent = new Intent(context, MainActivity.class);
Log.d("Hay9","DCM9");
PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);
Log.d("Hay10","DCM10");
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,"default")
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("Notification1")
.setContentText(message)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(pendingIntent);
Log.d("Hay11","DCM11");
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Log.d("Hay12","DCM12");
notificationManager.notify(NotiID++,builder.build());
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用日志调试,我认为问题是关于NotificationManager方法.这是日志:
05-23 17:23:30.774 18668-18668/com.example.user.estimotebeacon D/Hay8: DCM8
05-23 17:23:30.774 18668-18668/com.example.user.estimotebeacon D/Hay9: DCM9
05-23 17:23:30.776 18668-18668/com.example.user.estimotebeacon D/Hay10: DCM10
05-23 17:23:30.780 18668-18668/com.example.user.estimotebeacon D/Hay11: DCM11
05-23 17:23:30.781 18668-18668/com.example.user.estimotebeacon D/Hay12: DCM12
05-23 17:23:30.788 18668-18668/com.example.user.estimotebeacon E/NotificationManager: notifyAsUser: tag=null, id=1, user=UserHandle{0}
05-23 17:23:30.798 18668-18668/com.example.user.estimotebeacon D/Hay20: DCM20
05-23 17:23:30.859 …Run Code Online (Sandbox Code Playgroud) 我的问题是 getTag() 是在 null 方法上调用的。在下面的 logcat 中说。(我的应用程序已经有了 setTag() 然后是 getTag()。
我有一个这样的适配器代码 ListView :
public BeaconListAdapter(Activity context){
this.inflater = LayoutInflater.from(context);
this.beacons = new ArrayList<>();
}
public void replaceWith(Collection<com.estimote.coresdk.recognition.packets.Beacon> newBeacons){
this.beacons.clear();
this.beacons.addAll(newBeacons);
notifyDataSetChanged();
}
@Override
public int getCount() {
return beacons.size();
}
@Override
public com.estimote.coresdk.recognition.packets.Beacon getItem(int position) {
return beacons.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflateRequires(convertView);
bind(getItem(position),convertView);
return convertView;
}
private void bind(final com.estimote.coresdk.recognition.packets.Beacon beacon, …Run Code Online (Sandbox Code Playgroud)