我正在尝试从服务中获取数据并将其传递给通知。但是当我在真实设备上运行它时,它只是在通知中显示“已向您发送朋友请求”,数据消失了。然后我在 logcat 中发现了问题输出如下所示:
日志输出:
11-19 23:12:18.344: D/dataServices1(17701): admin*admin*
11-19 23:12:18.344: D/dataServices2(17701): [Ljava.lang.String;@40d9f0d8
11-19 23:12:18.344: D/dataServices3(17701): nulladmin,admin,
11-19 23:12:18.344: D/dataServices3(17701): ,
admin*admin* < 它在这里发送了两个数据。
所以我的问题是如何将它从“[Ljava.lang.String;@40da8e78”转换为“admin”以及为什么它只显示“[Ljava.lang.String;@40da8e78”而不是两次?像 [Ljava.lang.String;@40da8e78 [Ljava.lang.String;@40da8e78...为什么“str”(dataServices3) 输出显示为这样?
这是代码:
String datapassed;
String str = "";
String[] data;
int dlength;
public void onReceive(Context context, Intent intent) {
datapassed = intent.getStringExtra("DATAPASSED");
if(datapassed.length()>0){
//update from here
data = datapassed.split("[*]");
dlength = data.length;
for(int i=0;i<dlength;i++){
if(i==dlength-1){
str += String.valueOf(data[i]);
}else{
str += String.valueOf(data[i]) + ",";
}
Log.d("dataServices3",str);
displayNotification();
}
str = "";
Log.d("dataServices1",datapassed);
Log.d("dataServices2",data.toString());
//to here
}
}
};
protected void displayNotification(){
Intent i = new Intent(this,NotificationView.class);
i.putExtra("notification", notification);
PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
NotificationManager mnotis =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notis = new Notification(R.drawable.ic_launcher,"Reminder:You have " + dlength + " new friend request",System.currentTimeMillis());
notis.setLatestEventInfo(this,"Friend Request", str + "has sent you a friend request",pi);
notis.vibrate = new long[]{100,250,100,500};
mnotis.notify(0, notis);
}
这是运行后的 logcat 错误输出:
11-19 23:28:46.388: E/ExternalAccountType(11253): Unsupported attribute readOnly
11-19 23:28:46.648: E/ExternalAccountType(11253): Unsupported attribute readOnly
11-19 23:28:57.218: E/MediaProvider(19282): invalid album art, error creating album thumb file