安卓WIFI密码破解工具编写初探
http://www.eoeandroid.com/thread-207054-1-1.html

拉响手机QQ安全警报:聊天记录查看器的编写
http://www.eoeandroid.com/thread-207064-1-1.html

在GridView中实现单选或多选功能
http://www.eoeandroid.com/thread-207099-1-1.html

根据别人的代码写了一个demo,是短信快速回复的功能,主要是学习了服务和广播监听的简单用法

主界面
SmsReceiverActivity.java

package zdq.msg;   import android.app.Activity;   import android.app.AlertDialog;   import android.content.DialogInterface;   import android.content.Intent;   import android.os.Bundle;   import android.widget.Button;   import android.widget.Toast;   import android.view.Menu;   import android.view.MenuItem;   import android.view.View;   import android.view.View.OnClickListener;   public class SmsReceiverActivity extends Activity {     private Button bt01;         @Override       public void onCreate(Bundle savedInstanceState) {           super.onCreate(savedInstanceState);           setContentView(R.layout.main);                      getview();                      bt01.setOnClickListener(bt01_       }             private void getview(){        bt01=(Button)findViewById(R.id.bt01);       }             private OnClickListener bt01_onclick=new OnClickListener(){     @Override     public void onClick(View v) {      if(bt01.getText().equals(getResources().getString(R.string.bt01))){       Intent intent = new Intent();       intent.setClass(SmsReceiverActivity.this, Smsservice.class);       startService(intent);       bt01.setText(R.string.bt02);       Toast.makeText(SmsReceiverActivity.this, "打开监听", Toast.LENGTH_SHORT).show();            }else{       Intent intent = new Intent();       intent.setClass(SmsReceiverActivity.this, Smsservice.class);       stopService(intent);       bt01.setText(R.string.bt01);       Toast.makeText(SmsReceiverActivity.this, "关闭监听", Toast.LENGTH_SHORT).show();      }     }       };                   public boolean onCreateOptionsMenu(Menu menu){        menu.add(0,0,0,R.string.about);        menu.add(0,1,1,R.string.exit);             return super.onCreateOptionsMenu(menu);       }             public boolean onOptionsItemSelected(MenuItem item){        super.onOptionsItemSelected(item);        switch(item.getItemId()){        case 0:         openDialog();         break;        case 1:         finish();         break;        }        return true;       }             private void openDialog(){        new AlertDialog.Builder(this)        .setTitle(R.string.about)        .setMessage(R.string.message)        .setPositiveButton(R.string.ok,          new DialogInterface.OnClickListener() {        @Override        public void onClick(DialogInterface dialog, int which) {                 }       }          ).show();       }   }   

短信回复对话框

package zdq.msg;   import android.app.Activity;   import android.content.Context;   import android.content.Intent;   import android.os.Bundle;   import android.telephony.SmsManager;   import android.view.View;   import android.view.View.OnClickListener;   import android.widget.Button;   import android.widget.EditText;   public class SMSToast extends Activity {   private Button bt_send;   private Button bt_no;   private EditText et_addr;   private EditText et_msg;   private String addr;   @Override       public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);           setContentView(R.layout.toast);          getview();          Intent intent = this.getIntent();     addr = (String) intent.getSerializableExtra("addr");     et_addr.setText(addr);     et_msg.setText(getResources().getString(R.string.msg_body));          getclick();        }     private void getview(){     bt_send=(Button)findViewById(R.id.bt_send);     bt_no=(Button)findViewById(R.id.bt_no);     et_addr=(EditText)findViewById(R.id.et_addr);     et_msg=(EditText)findViewById(R.id.et_msg);   }     private void getclick(){     bt_send.setOnClickListener(bt_send_     bt_no.setOnClickListener(bt_no_   }     private OnClickListener bt_send_onclick=new OnClickListener(){     @Override     public void onClick(View v) {      SendSms(SMSToast.this,et_addr.getText().toString(),et_msg.getText().toString());      finish();     }   };     private OnClickListener bt_no_onclick=new OnClickListener(){     @Override     public void onClick(View v) {      finish();     }   };     /**     * 发送短信     * @param context     * @param addre     * @param mess     */   public void SendSms(Context context,String addre, String mess)   {           SmsManager manager = SmsManager.getDefault();           manager.sendTextMessage(addre, null, mess, null, null);   }   }   

短信接收类

package zdq.msg;   import android.content.BroadcastReceiver;   import android.content.Context;   import android.content.Intent;   import android.os.Bundle;   import android.telephony.SmsMessage;   import android.util.Log;   public class SmsReceiver extends BroadcastReceiver{   private static final String strRes = "android.provider.Telephony.SMS_RECEIVED";   private static final String TAG = "LocalService";   private String addr;     @Override   public void onReceive(Context context, Intent intent) {   /*   * 判断是否是SMS_RECEIVED事件被触发  */  if (intent.getAction().equals(strRes)) {          Bundle bundle = intent.getExtras();          if (bundle != null) {            Object[] pdus = (Object[]) bundle.get("pdus");            SmsMessage[] msg = new SmsMessage[pdus.length];            for (int i = 0; i < pdus.length; i++) {       msg[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);      }            if(msg.length!=0){       Log.i(TAG, "快速回复模式");       for (SmsMessage currMsg : msg) {                addr=currMsg.getDisplayOriginatingAddress();                Intent mBootIntent = new Intent(context, SmsReceiver.class);        mBootIntent = new Intent(context, SMSToast.class);              mBootIntent.setAction("android.intent.action.MAIN");              mBootIntent.addCategory("android.intent.category.LAUNCHER");                mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                            Bundle mBundle = new Bundle();                mBundle.putSerializable("addr",addr);              mBootIntent.putExtras(mBundle);                              context.startActivity(mBootIntent);       }      }     }   }   }   }   

服务

package zdq.msg;   import android.app.Service;   import android.content.Intent;   import android.content.IntentFilter;   import android.os.IBinder;   import android.util.Log;   import android.view.View;   import android.widget.Toast;   public class Smsservice extends Service {     private boolean isregiset = false;       private static final String MSG_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";   private static final String TAG = "LocalService";   private SmsReceiver recevier;     @Override   public IBinder onBind(Intent arg0) {     Log.i(TAG, "onBind");     return null;   }     @Override   public void onDestroy()   {     Log.i(TAG, "onDestroy");     super.onDestroy();     unregisterReceiver(recevier);   }     @Override   public int onStartCommand(Intent intent, int flags, int startId)   {     Log.i(TAG, "onStartCommand");     return super.onStartCommand(intent, flags, startId);   }     public void onStart(Intent intent,int startId){     Log.i(TAG, "onStart");     super.onStart(intent, startId);          recevier=new SmsReceiver();     IntentFilter intentFilter = new IntentFilter(MSG_RECEIVED);        intentFilter.setPriority(1000);//设置优先级最大        registerReceiver(recevier , intentFilter);        isregiset=true;   }     public void onCreate(){     Log.i(TAG, "onCreate");     super.onCreate();   }         public void regiset(View v) {           IntentFilter filter = new IntentFilter(MSG_RECEIVED);           filter.setPriority(1000);//设置优先级最大           registerReceiver(recevier, filter);           isregiset = true;           Toast.makeText(this, "0", 0).show();       }             public void unregiset(View v) {           if (recevier != null && isregiset) {               unregisterReceiver(recevier);               isregiset = false;               Toast.makeText(this, "成功", 0).show();           } else               Toast.makeText(this, "失败", 0).show();       }   }

mail.xml:

<?xml version="1.0" encoding="utf-8"?>   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"       android:layout_width="fill_parent"       android:layout_height="fill_parent"       android:orientation="vertical" >       <Button           android:id="@+id/bt01"           android:layout_width="fill_parent"           android:layout_height="wrap_content"           android:text="@string/bt01" />   </LinearLayout>   

toast.xml:

<?xml version="1.0" encoding="utf-8"?>   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"       android:layout_width="240dp"       android:layout_height="300dp"       android:orientation="vertical" >         <EditText           android:id="@+id/et_addr"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           />             <EditText           android:id="@+id/et_msg"           android:layout_width="fill_parent"           android:layout_height="160dp"           />             <RadioGroup android:id="@+id/ataawGroup"         android:layout_width="fill_parent"         android:layout_height="60dp"          android:orientation="horizontal"          >             <Button           android:id="@+id/bt_send"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:text="@string/bt_send" />       <Button           android:id="@+id/bt_no"           android:layout_width="wrap_content"           android:layout_height="wrap_content"           android:text="@string/bt_no" />             </RadioGroup>         </LinearLayout>   

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>   <manifest xmlns:android="http://schemas.android.com/apk/res/android"       package="zdq.msg"       android:versionCode="1"       android:versionName="1.0" >       <uses-sdk android:minSdkVersion="7" />         <uses-permission android:name="android.permission.SEND_SMS" />       <uses-permission android:name="android.permission.READ_SMS" />       <uses-permission android:name="android.permission.WRITE_SMS" />       <uses-permission android:name="android.permission.RECEIVE_SMS" />       <uses-permission android:name="android.permission.READ_CONTACTS"/>             <application           android:icon="@drawable/ic_launcher"           android:label="@string/app_name" >           <activity               android:label="@string/app_name"               android:name=".SmsReceiverActivity" >               <intent-filter >                   <action android:name="android.intent.action.MAIN" />                   <category android:name="android.intent.category.LAUNCHER" />               </intent-filter>           </activity>                      <activity android:name=".SMSToast"               android:theme="@android:style/Theme.Dialog">           </activity>                      <service android:name=".Smsservice">      <intent-filter>       <action android:name="zdq.msg.Smsservice" />       <category android:name="android.intent.category.default" />     </intent-filter>        </service>                      </application>   </manifest>   

短信快速回复(源码)_android开发

 

短信快速回复(源码)_移动开发_02

 

原文链接:http://www.eoeandroid.com/thread-206880-1-1.html