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

很久以前写过的一个Android程序,主要用到了ListView,ContentProvider,solite数据库和Java网络通信实现了基于第三方API的飞信群发助手,实现了飞信的添加好友,发送飞信和飞信群发功能,可以作为参考,源码我已经上传,下载地址我会放在下面,供大家下载学习。本人小菜一个。。。。欢迎大家拍砖~~~

这是程序的主界面:

主界面源代码,FetionSend.java

package com.huangcheng.mainFrame;      import java.io.BufferedReader;   import java.io.InputStreamReader;   import java.net.HttpURLConnection;   import java.net.URL;   import java.util.regex.Pattern;      import android.app.Activity;   import android.app.AlertDialog;   import android.app.ProgressDialog;   import android.app.AlertDialog.Builder;   import android.content.Context;   import android.content.DialogInterface;   import android.content.Intent;   import android.content.SharedPreferences;   import android.content.SharedPreferences.Editor;   import android.os.Bundle;   import android.os.Handler;   import android.os.Message;   import android.view.View;   import android.view.View.OnClickListener;   import android.widget.Button;   import android.widget.EditText;   import android.widget.Toast;      import com.huangcheng.FetionAdd.AddPerson;   import com.huangcheng.FetionSend.SendPerson;      public class FetionSend extends Activity {       /** Called when the activity is first created. */          // private final boolean state=false;;           private final int test_fail = 0;       private final int test_true = 1;          private Button add, send, quit, save;       private EditText user, pwd;       private String username, password;          private ProgressDialog progressDialog;          @Override       public void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.main);           add = (Button) findViewById(R.id.AddPeople);           send = (Button) findViewById(R.id.SendPeople);           quit = (Button) findViewById(R.id.Quit);           save = (Button) findViewById(R.id.SaveUser);           user = (EditText) findViewById(R.id.feitionnumber);           pwd = (EditText) findViewById(R.id.feitionpwd);           SharedPreferences sharedPreferences = getSharedPreferences(                   "Fetion_Send", Context.MODE_PRIVATE);           username = sharedPreferences.getString("username""");           user.setText(username);           password = sharedPreferences.getString("password""");           pwd.setText(password);           save.setOnClickListener(new OnClickListener() {                  @Override               public void onClick(View arg0) {                   // TODO Auto-generated method stub                    TestLogin();               }              });           add.setOnClickListener(new OnClickListener() {                  @Override               public void onClick(View arg0) {                   // TODO Auto-generated method stub                    SharedPreferences sharedPreferences_test = getSharedPreferences(                           "test", Context.MODE_PRIVATE);                   boolean test = sharedPreferences_test.getBoolean("test"false);                   if (user.getText().length() == 0 || pwd.getText().length() == 0                           || isNumeric(user.getText().toString()) || !test) {                       AlertDialog.Builder builder = new Builder(FetionSend.this);                       builder.setMessage("您飞信用户名或者密码输入有误,确认要添加飞信好友么?");                       builder.setTitle("提示");                       builder.setPositiveButton("确认",                               new DialogInterface.OnClickListener() {                                      @Override                                   public void onClick(DialogInterface dialog,                                           int arg1) {                                       // TODO Auto-generated method stub                                        dialog.dismiss();                                       Intent intent = new Intent();                                       intent.setClass(FetionSend.this,                                               AddPerson.class);                                       startActivity(intent);                                   }                               });                       builder.setNegativeButton("取消",                               new DialogInterface.OnClickListener() {                                   @Override                                   public void onClick(DialogInterface dialog,                                           int arg1) {                                       // TODO Auto-generated method stub                                        dialog.dismiss();                                   }                               });                       builder.create().show();                   } else {                       Intent intent = new Intent();                       intent.setClass(FetionSend.this, AddPerson.class);                       startActivity(intent);                   }               }           });           send.setOnClickListener(new OnClickListener() {                  @Override               public void onClick(View arg0) {                   // TODO Auto-generated method stub                    SharedPreferences sharedPreferences_test = getSharedPreferences(                           "test", Context.MODE_PRIVATE);                   boolean test = sharedPreferences_test.getBoolean("test"false);                   if (user.getText().length() == 0 || pwd.getText().length() == 0                           || isNumeric(user.getText().toString()) || !test) {                       AlertDialog.Builder builder = new Builder(FetionSend.this);                       builder.setMessage("您飞信用户名或者密码输入有误,确认要发送飞信么?");                       builder.setTitle("提示");                       builder.setPositiveButton("确认",                               new DialogInterface.OnClickListener() {                                      @Override                                   public void onClick(DialogInterface dialog,                                           int arg1) {                                       // TODO Auto-generated method stub                                        dialog.dismiss();                                       Intent intent = new Intent();                                       intent.setClass(FetionSend.this,                                               SendPerson.class);                                       startActivity(intent);                                   }                               });                       builder.setNegativeButton("取消",                               new DialogInterface.OnClickListener() {                                   @Override                                   public void onClick(DialogInterface dialog,                                           int arg1) {                                       // TODO Auto-generated method stub                                        dialog.dismiss();                                   }                               });                       builder.create().show();                   } else {                       Intent intent = new Intent();                       intent.setClass(FetionSend.this, SendPerson.class);                       startActivity(intent);                   }               }           });           quit.setOnClickListener(new OnClickListener() {                  @Override               public void onClick(View arg0) {                   // TODO Auto-generated method stub                    AlertDialog.Builder builder = new Builder(FetionSend.this);                   builder.setMessage("确认退出吗?");                   builder.setTitle("提示");                   builder.setPositiveButton("确认",                           new DialogInterface.OnClickListener() {                                  @Override                               public void onClick(DialogInterface dialog, int arg1) {                                   // TODO Auto-generated method stub                                    dialog.dismiss();                                   FetionSend.this.finish();                                   System.exit(0);                               }                           });                   builder.setNegativeButton("取消",                           new DialogInterface.OnClickListener() {                               @Override                               public void onClick(DialogInterface dialog, int arg1) {                                   // TODO Auto-generated method stub                                    dialog.dismiss();                               }                           });                   builder.create().show();               }           });       }          // @Override        // protected void onStop() {        // // TODO Auto-generated method stub        // super.onStop();        // SharedPreferences        // sharedPreferences_save=getSharedPreferences("Fetion_Send",Context.MODE_PRIVATE);        // Editor editor=sharedPreferences_save.edit();        // editor.putString("username",user.getText().toString());        // editor.putString("password",pwd.getText().toString());        // }        private final Handler handler = new Handler() {           public void handleMessage(Message msg) {               super.handleMessage(msg);               switch (msg.what) {               case test_fail:                   // 添加失败                    progressDialog.dismiss();                   Toast.makeText(FetionSend.this"存储飞信号和密码失败,飞信号或密码错误,请重试!",                           Toast.LENGTH_LONG).show();                   break;               case test_true:                   // 添加失败                    progressDialog.dismiss();                   Toast.makeText(FetionSend.this"存储飞信号和密码成功", Toast.LENGTH_LONG)                           .show();                   break;               }           };       };          public static boolean isNumeric(String str) {           Pattern pattern = Pattern.compile("[0-9]*");           return !pattern.matcher(str).matches();       }          public void TestLogin() {           progressDialog = ProgressDialog.show(FetionSend.this"联网中...",                   "请稍等,正在验证飞信号和密码...");           SharedPreferences sharedPreferences_save = getSharedPreferences(                   "Fetion_Send", Context.MODE_PRIVATE);           Editor editor_save = sharedPreferences_save.edit();           editor_save.putString("username", user.getText().toString());           editor_save.putString("password", pwd.getText().toString());           editor_save.commit();           username = sharedPreferences_save.getString("username""");           password = sharedPreferences_save.getString("password""");           Runnable r = new Runnable() {                  @Override               public void run() {                   // TODO Auto-generated method stub                    try {                       String resultData = "";                       String httpurl = "http://lab.3haku.net/f/do?phone="                               + username + "&pwd=" + password + "&add="                               + username;                       URL url = new URL(httpurl);                       // 使用HttpURLConnection打开连接                        HttpURLConnection urlConn = (HttpURLConnection) url                               .openConnection();                       // 得到读取的内容(流)                        InputStreamReader in = new InputStreamReader(                               urlConn.getInputStream());                       // 为输出创建BufferedReader                        BufferedReader buffer = new BufferedReader(in);                       String inputLine = null;                       // 使用循环来读取获得的数据                        while (((inputLine = buffer.readLine()) != null)) {                           // 我们在每一行后面加上一个"\n"来换行                            resultData += inputLine + "\n";                       }                       // 关闭InputStreamReader                        in.close();                       // 关闭http连接                        urlConn.disconnect();                       System.out.println(resultData.substring(8693));                       System.out.println(resultData);                       if (resultData.substring(8693).equals("success")) {                           SharedPreferences sharedPreferences_test = getSharedPreferences(                                   "test", Context.MODE_PRIVATE);                           Editor editor = sharedPreferences_test.edit();                           editor.putBoolean("test"true);                           editor.commit();                           Message msg = handler.obtainMessage();                           msg.what = test_true;                           handler.sendMessage(msg);                           SharedPreferences sharedPreferences_save = getSharedPreferences(                                   "Fetion_Send", Context.MODE_PRIVATE);                           Editor editor_save = sharedPreferences_save.edit();                           editor_save.putString("username", user.getText()                                   .toString());                           editor_save.putString("password", pwd.getText()                                   .toString());                           editor_save.commit();                          } else {                           // SharedPreferences                            // sharedPreferences_test=getSharedPreferences("test",Context.MODE_PRIVATE);                            // Editor editor=sharedPreferences_test.edit();                            // editor.putBoolean("test", false);                            // editor.commit();                            Message msg = handler.obtainMessage();                           msg.what = test_fail;                           handler.sendMessage(msg);                       }                   } catch (Exception e) {                       // TODO: handle exception                        e.printStackTrace();                   }               }           };           Thread testThread = new Thread(r);           testThread.start();       }   }  

这个界面展示了基本所有功能,验证你的飞信号码和密码是否正确,是否要添加飞信好友,是否要进行飞信群发。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ppjzy.html