java如何在安卓中将通知发送到多个检查值
您好,在下面我正在创建一个群组,我正在传递群组名称,其中包含该群组中的好友数。
现在我的问题是friendAdapter.getCheckedItems()
使用这个方法,我得到的是唯一的检查值。现在,我只想将通知发送给组消息中的已选中好友,消息应为groupname和username
java
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (安卓.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
setContentView(R.layout.group_list_screen);
Button create=(Button)findViewById(R.id.create);
friendAdapter = new FriendListAdapter(this);
create.setOnClickListener(new OnClickListener() {
@SuppressWarnings({ "unused", "unchecked" })
@Override
public void onClick(View v) {
String groupname = getIntent().getStringExtra("nick");
try {
imService=Login.imService;
String result1 = imService.CreateGroup(groupname,imService.getUsername(),friendAdapter.getCheckedItems());
System.out.println(result1);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(), "Group Created Sucessfully",Toast.LENGTH_LONG).show();
}
});
imService。CreateGroup()。java
public String CreateGroup(String groupname,String username,
ArrayList<FriendInfo> result) throws UnsupportedEncodingException {
this.groupname=groupname;
List<String> usersName = new ArrayList<String>();
for (int i = 0; i < result.size(); i++) {
usersName.add(result.get(i).userName);
}
String params = "groupname="+ URLEncoder.encode(this.groupname,"UTF-8") +
"&username="+ URLEncoder.encode(this.username,"UTF-8") +
"&password="+ URLEncoder.encode(this.password,"UTF-8") +
"&friendUserName=" +usersName.toString().replaceAll(" ","")+
"&action=" + URLEncoder.encode("CreateGroup","UTF-8")+
"&";
Log.i("PARAMS", params);
return socketOperator.sendHttpRequest(params);
}
sendmessage()
public void sendmessage(FriendInfo[] result)
{
if (result != null)
{
NotificationManager NM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (result.length > 0)
{
String tmp = new String();
for (int j = 0; j < result.length; j++) {
tmp = tmp.concat(result[j].userName).concat(",");
}
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.stat_sample)
.setContentTitle(getText(R.string.new_friend_request_exist));
@SuppressWarnings("unused")
Notification notification = new Notification(R.drawable.stat_sample,
getText(R.string.new_friend_request_exist),
System.currentTimeMillis());
String groupname = getIntent().getStringExtra("nick");
Intent i = new Intent(this, FriendList.class);
i.putExtra(FriendInfo.FRIEND_LIST, tmp);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
i, 0);
mBuilder.setContentText("You have new Group request"+groupname);
mBuilder.setContentIntent(contentIntent);
NM.notify(R.string.new_group_request_exist, mBuilder.build());
}
else
{
NM.cancel(R.string.new_group_request_exist);
}
}
}
# 1 楼答案
“组”消息发送给个人,而不是个人的“组”。在您的消息传递协议中,您可以(并且应该)包含组参与者列表(用于用户和“回复”目的)
但是,如果您试图“发送到一个组”,那么您正在使用的消息服务需要支持这一点。此外,“组名”通常在消息传递协议中不受支持-组名是用户的便利,而不是其他组成员的便利
您没有指定如何发送消息-短信、聊天等
如果您想知道“检查”了哪些用户,只需在适配器上迭代(它应该包含所有数据)或在检查项目时维护一个列表
编辑:
您的
sendMessage
方法正在为用户通知设备-它不会向其他设备发送“通知”。您需要使用短信、谷歌云消息(GCM)、亚马逊通知或其他方式“发送”消息(然后设备和/或应用程序将在收到消息时发出通知)