你好,游客 登录 注册 搜索
背景:
阅读新闻

Android飞信群发助手【附源码】

[日期:2012-05-27] 来源:Linux社区  作者:hc260164797 [字体:大 中 小]

这个是飞信群发组的界面:SendGroup.java ,实现飞信群发功能:

  1. package com.huangcheng.FetionSend;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.HashMap;  
  5.   
  6. import com.huangcheng.mainFrame.R;  
  7. import com.huangcheng.sql.GroupOfPeople;  
  8.   
  9. import Android.app.Activity;  
  10. import android.app.AlertDialog;  
  11. import android.app.AlertDialog.Builder;  
  12. import android.content.DialogInterface;  
  13. import android.content.Intent;  
  14. import android.database.Cursor;  
  15. import android.database.sqlite.SQLiteDatabase;  
  16. import android.os.Bundle;  
  17. import android.view.ContextMenu;  
  18. import android.view.Menu;  
  19. import android.view.MenuItem;  
  20. import android.view.View;  
  21. import android.view.ContextMenu.ContextMenuInfo;  
  22. import android.view.View.OnCreateContextMenuListener;  
  23. import android.widget.AdapterView;  
  24. import android.widget.AdapterView.OnItemLongClickListener;  
  25. import android.widget.ListView;  
  26. import android.widget.SimpleAdapter;  
  27. import android.widget.Toast;  
  28.   
  29. public class SendGroup extends Activity{  
  30.     private final int item1=Menu.FIRST;  
  31.     private final int item2=Menu.FIRST+1;  
  32.     private final int item3=Menu.FIRST+2;  
  33.     private final int item4=Menu.FIRST+3;  
  34.     private ListView ListGroup;  
  35.     private SimpleAdapter simpleAdapter;  
  36.     private String name_group=" ";  
  37.     @Override  
  38.     protected void onCreate(Bundle savedInstanceState) {  
  39.         // TODO Auto-generated method stub   
  40.         super.onCreate(savedInstanceState);  
  41.         setContentView(R.layout.sendgroup);  
  42.         ListGroup=(ListView)findViewById(R.id.ListGroup);  
  43.         GroupOfPeople dbHelper=new GroupOfPeople(SendGroup.this, "Group");  
  44.         SQLiteDatabase dbread=dbHelper.getReadableDatabase();  
  45.         Cursor cursor=dbread.query("groupName", new String[]{"id","group_name"},null,null, null, null, null);  
  46.         if(cursor.getCount()==0){  
  47.             Toast.makeText(SendGroup.this,"没有群存在",500).show();  
  48. //          setContentView(R.layout.nullview);   
  49.         }  
  50.         else{  
  51. //          cursor.moveToFirst();   
  52.             ArrayList<HashMap<String,String>> listItem=new ArrayList<HashMap<String,String>>();  
  53. //          HashMap<String, String> map1=new HashMap<String,String>();   
  54. //          map1.put("GROUPNAME",cursor.getString(cursor.getColumnIndex("group_name")));   
  55. //          listItem.add(map1);   
  56.             while(cursor.moveToNext()){  
  57.                 HashMap<String, String> map=new HashMap<String,String>();  
  58.                 map.put("GROUPNAME",cursor.getString(cursor.getColumnIndex("group_name")));  
  59.                 listItem.add(map);  
  60.             }  
  61.             simpleAdapter=new SimpleAdapter(this, listItem, R.layout.grouplist, new String[]{"GROUPNAME"}, new int[]{R.id.NameOfGroup});  
  62.             ListGroup.setAdapter(simpleAdapter);  
  63.             simpleAdapter.notifyDataSetChanged();  
  64.             ListGroup.setOnItemLongClickListener(new OnItemLongClickListener() {  
  65.   
  66.                 @Override  
  67.                 public boolean onItemLongClick(AdapterView<?> arg0, View arg1,  
  68.                         int arg2, long arg3) {  
  69.                     // TODO Auto-generated method stub   
  70.                     @SuppressWarnings("unchecked")  
  71.                     HashMap<String, String> mapgroup= (HashMap<String, String>) ListGroup.getItemAtPosition(arg2);  
  72.                     name_group=mapgroup.get("GROUPNAME");  
  73.                     System.out.println("SendGroup name_group="+name_group);  
  74.                     return false;  
  75.                 }  
  76.             });  
  77.             ListGroup.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {  
  78.                   
  79.                 @Override  
  80.                 public void onCreateContextMenu(ContextMenu menu, View arg1,  
  81.                         ContextMenuInfo arg2) {  
  82.                     // TODO Auto-generated method stub   
  83.                     menu.setHeaderTitle(name_group);  
  84.                     menu.add(0, item1, 0, "发送消息");  
  85.                     menu.add(0, item2, 0, "查看群组");  
  86.                     menu.add(0, item3, 0, "删除群组");  
  87.                     menu.add(0, item4, 0, "取消操作");  
  88.                 }  
  89.             });   
  90.             }  
  91.             dbread.close();  
  92.             dbHelper.close();  
  93.     }  
  94.     @Override    
  95.     public boolean onContextItemSelected(MenuItem item) {    
  96.         switch (item.getItemId()) {    
  97.         case item1:    
  98.             //发送消息   
  99.             System.out.println("发送消息"+name_group);  
  100.             Intent m=new Intent();  
  101.             m.putExtra("groupname", name_group);  
  102.             m.setClass(SendGroup.this, SendMessage.class);  
  103.             startActivity(m);  
  104.             break;    
  105.         case item2:  
  106.             //查看群成员   
  107.             System.out.println("查看群成员"+name_group);  
  108.             Intent p=new Intent();  
  109.             p.putExtra("groupname", name_group);  
  110.             p.setClass(SendGroup.this, PersonInGroup.class);  
  111.             startActivity(p);  
  112.             break;    
  113.         case item3:  
  114.             //删除群组   
  115.             System.out.println("删除群组"+name_group);  
  116.             AlertDialog.Builder builder = new Builder(SendGroup.this);  
  117.             builder.setMessage("确认删除吗?");  
  118.             builder.setTitle("提示");  
  119.             builder.setPositiveButton("确认",new DialogInterface.OnClickListener() {  
  120.                   
  121.                 @Override  
  122.                 public void onClick(DialogInterface dialog, int arg1) {  
  123.                     // TODO Auto-generated method stub   
  124.                     GroupOfPeople dbHelper=new GroupOfPeople(SendGroup.this, "Group");  
  125.                     SQLiteDatabase dbwrite=dbHelper.getWritableDatabase();  
  126. //                  simpleAdapter.getItem(position);   
  127.                     SQLiteDatabase dbread=dbHelper.getReadableDatabase();  
  128. //                  Cursor cursor=dbread.query("groupPerson", new String[]{"id","groupname"},"groupname="+"'"+name_group+"'",null, null, null, null);   
  129.                     dbwrite.delete("groupPerson", "groupname="+"'"+name_group+"'", null);  
  130. //                  Cursor cursor2=dbread.query("groupName", new String[]{"id","group_name"},"group_name="+"'"+name_group+"'",null, null, null, null);   
  131.                     dbwrite.delete("groupName", "group_name="+"'"+name_group+"'", null);  
  132.                     simpleAdapter.notifyDataSetChanged();  
  133.                     dbwrite.close();  
  134.                     dbread.close();  
  135.                     dbHelper.close();  
  136.                     dialog.dismiss();  
  137.                     SendGroup.this.onRestart();  
  138.                 }  
  139.             });  
  140.             builder.setNegativeButton("取消",new DialogInterface.OnClickListener(){  
  141.                 @Override  
  142.                 public void onClick(DialogInterface dialog, int arg1) {  
  143.                     // TODO Auto-generated method stub   
  144.                     dialog.dismiss();  
  145.                 }  
  146.             });  
  147.             builder.create().show();  
  148.             break;  
  149.         case item4:  
  150.             System.out.println("取消操作"+name_group);  
  151.             break;   
  152.         }    
  153.         return true;    
  154.     }  
  155.     @Override  
  156.     protected void onRestart() {  
  157.         // TODO Auto-generated method stub   
  158.         super.onRestart();  
  159.         setContentView(R.layout.sendgroup);  
  160.         ListGroup=(ListView)findViewById(R.id.ListGroup);  
  161. //      ListGroup=(ListView)findViewById(R.id.ListGroup);   
  162.         GroupOfPeople dbHelper=new GroupOfPeople(SendGroup.this, "Group");  
  163.         SQLiteDatabase dbread=dbHelper.getReadableDatabase();  
  164.         Cursor cursor=dbread.query("groupName", new String[]{"id","group_name"},null,null, null, null, null);  
  165.         if(cursor.getCount()==0){  
  166.             Toast.makeText(SendGroup.this,"没有群存在",500).show();  
  167. //          setContentView(R.layout.nullview);   
  168.         }  
  169.         else{  
  170. //          cursor.moveToFirst();   
  171.             ArrayList<HashMap<String,String>> listItem=new ArrayList<HashMap<String,String>>();  
  172. //          HashMap<String, String> map1=new HashMap<String,String>();   
  173. //          map1.put("GROUPNAME",cursor.getString(cursor.getColumnIndex("group_name")));   
  174. //          listItem.add(map1);   
  175.             while(cursor.moveToNext()){  
  176.                 HashMap<String, String> map=new HashMap<String,String>();  
  177.                 map.put("GROUPNAME",cursor.getString(cursor.getColumnIndex("group_name")));  
  178.                 listItem.add(map);  
  179.             }  
  180.             simpleAdapter=new SimpleAdapter(this, listItem, R.layout.grouplist, new String[]{"GROUPNAME"}, new int[]{R.id.NameOfGroup});  
  181.             ListGroup.setAdapter(simpleAdapter);  
  182.             simpleAdapter.notifyDataSetChanged();  
  183.             ListGroup.setOnItemLongClickListener(new OnItemLongClickListener() {  
  184.   
  185.                 @Override  
  186.                 public boolean onItemLongClick(AdapterView<?> arg0, View arg1,  
  187.                         int arg2, long arg3) {  
  188.                     // TODO Auto-generated method stub   
  189.                     @SuppressWarnings("unchecked")  
  190.                     HashMap<String, String> mapgroup= (HashMap<String, String>) ListGroup.getItemAtPosition(arg2);  
  191.                     name_group=mapgroup.get("GROUPNAME");  
  192.                     System.out.println("SendGroup name_group="+name_group);  
  193.                     return false;  
  194.                 }  
  195.             });  
  196.             ListGroup.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {  
  197.                   
  198.                 @Override  
  199.                 public void onCreateContextMenu(ContextMenu menu, View arg1,  
  200.                         ContextMenuInfo arg2) {  
  201.                     // TODO Auto-generated method stub   
  202.                     menu.setHeaderTitle(name_group);  
  203.                     menu.add(0, item1, 0, "发送消息");  
  204.                     menu.add(0, item2, 0, "查看群组");  
  205.                     menu.add(0, item3, 0, "删除群组");  
  206.                     menu.add(0, item4, 0, "取消操作");  
  207.                 }  
  208.             });   
  209.             }  
  210.             dbread.close();  
  211.             dbHelper.close();  
  212.     }  
  213.     @Override  
  214.     protected void onResume() {  
  215.         // TODO Auto-generated method stub   
  216.         super.onResume();  
  217.         onRestart();  
  218.     }  
  219. }  

四个类实现本程序的基本框架,还有一些其他的比如发送飞信信息的线程类,数据库类,实现ListView效果的Adapter类,大家可以下载我的源码,源码地址是:

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2012年资料/5月/27日/Android飞信群发助手【附源码】/

更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11

linux
相关资讯       Android程序 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 哈哈 发表于 2012/5/28 10:21:46
楼主好人,高手