按钮点击通知不使用android中的服务发送到多个

时间:2015-02-19 10:42:57

标签: android notifications

嗨,我在点击按钮通知发送时使用groupname.but在我的groupdata中,tmp字符串中不包含任何用户,我想发送此字符串返回正确的用户。但是通知只发送一次。 但是,我想发送基于我想要通知的用户。

例如,如果用户名包含3个值,我想发送3次通知。但是当用户使用该帐户登录时,将显示该通知。

的java

    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(),
                                groupfriendAdapter.getCheckedItems());

                        List<String> usersName = new ArrayList<String>();
                        for (int i = 0; i < result.size(); i++) {
                            usersName.add(result.get(i).userName);
                            GroupList.this.groupdata(
                                    FriendController.getFriendsInfo(),usersName);   

                        }



                    } catch (UnsupportedEncodingException e) {

                        e.printStackTrace();
                    }


                    Toast.makeText(getApplicationContext(),
                            "Group Created Sucessfully", Toast.LENGTH_LONG).show();

                }

            });

        }
public void groupdata(FriendInfo[] friends, List<String> usersName) {
        if (friends != null) {
            groupfriendAdapter.setFriendList(friends);
            setListAdapter(groupfriendAdapter);
        }
    if (usersName!=null) {
        NotificationManager NM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  


            if (usersName.size() > 0) {
                String tmp = new String();
                for (int j = 0; j < usersName.size(); j++) {
                    tmp = tmp.concat(usersName.get(j)).concat(",");
                }
                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                        this).setSmallIcon(R.drawable.stat_sample)
                        .setContentTitle(
                                getText(R.string.new_friend_request_exist));
                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.USERNAME, tmp);


                PendingIntent contentIntent = PendingIntent.getActivity(this,
                        0, i, 0);

                mBuilder.setContentText("You have new group message"+groupname);

                mBuilder.setContentIntent(contentIntent);

                NM.notify(R.string.new_group_request_exist, mBuilder.build());
            } else {

                NM.cancel(R.string.new_group_request_exist);
            }
        }

0 个答案:

没有答案