我試圖從服務中獲取數據並將其傳遞給notification.But當我在真實設備上運行它時,它只是顯示「發送給您一個好友請求」的通知,數據消失了。然後我發現問題在logcat的和輸出被示出如下:如何轉換字符串?
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): ,
管理員* *管理員<它送到這裏的兩個數據。
所以我的問題是如何將其轉換爲「管理員」從「[Ljava.lang.String; @ 40da8e78」和爲什麼它只顯示「[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
我不知道,但嘗試更換將String.valueOf(數據[1])數據[I] –
粘貼logcate這裏 –
它的印刷,由於*** ***的數據是一個String [ ]不是一個字符串 另一方面,你真的想發送一個通知每個數據? 還是你想構建一個通知追加數據的不同部分 –