如何将通知发送到android中的多个已检查值

时间:2015-02-18 06:41:46

标签: java android android-notifications

嗨,在下面我正在创建组,因为我传递的组名与该组中的朋友没有。 现在我的问题是friendAdapter.getCheckedItems()使用这种方法我得到唯一的选中值。现在,我想将通知发送给组消息中只有已检查的朋友,应该是带有用户名的组名。

的java

protected void onCreate(Bundle savedInstanceState){       
        super.onCreate(savedInstanceState);

        if (android.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 个答案:

答案 0 :(得分:0)

&#34;组&#34;消息被发送给个人,而不是&#34;组&#34;个人在您的消息传递协议中,您可以(并且应该)包括组参与者列表(针对用户以及&#34;回复&#34;目的)。

但是如果你想&#34;发送给一个团体&#34;那么你正在使用的消息服务需要支持它。此外,&#34; GroupNames&#34;消息传递协议通常不支持 - 名称对用户而不是其他组成员来说是方便的。

您没有指定发送信息的方式 - 短信,聊天等

如果您想知道哪些用户已经过检查&#34;你只需要遍历适配器(它应该包含所有数据)或者在检查项目时维护一个列表。

编辑:

您的sendMessage方法正在通知设备用户 - 它不会发送&#34;通知&#34;到其他设备。您需要使用SMS,Google云消息传递(GCM),亚马逊通知或其他一些方式来发送&#34;消息(然后设备和/或应用程序将在收到消息时通知)。

相关问题