一生有你llx 阅读(73) 评论(0)

点击(此处)折叠或打开

  1. package com.example.incoming_number;

  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.net.DatagramPacket;
  5. import java.net.DatagramSocket;
  6. import java.net.ServerSocket;
  7. import java.net.Socket;

  8. import android.os.Bundle;
  9. import android.app.Activity;
  10. import android.content.ContentResolver;
  11. import android.content.Intent;
  12. import android.view.Menu;
  13. import android.view.View;
  14. import android.view.View.OnClickListener;
  15. import android.widget.Button;
  16. import android.widget.EditText;
  17. import android.widget.TextView;

  18. /*
  19.  *    APP_name:         incoming_number
  20.  *    AURHOR:            DDDDD
  21.  *    DATE:              2014-11-17
  22.  *    MODIFY:            2014-11-23 20:43
  23.  *    FUCTION:          get incoming number or message number and then send num and name to http server
  24.  *
  25.  *
  26.  * DESCRIPTION:
  27.  * 按下“开启服务”按钮,创建service,在service中创建一个broadcast
  28.  * 通过broadcast接收来电号码或者短信号码, 访问通讯录数据库,通过号码得到name    
  29.  * 通过post方法向http server 发送 num name
  30.  * 按下“关闭服务”按钮, service关闭,同时销毁broadcast
  31.  *    要访问网络、message、phoneState、通讯录数据库 需要添加一起权限
  32.  *     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  33.  *    <uses-permission android:name="android.permission.RECEIVE_SMS" />
  34.  *    <uses-permission android:name="android.permission.INTERNET"/>
  35.  *    <uses-permission android:name="android.permission.READ_CONTACTS"/>
  36.  */
  37. public class MainActivity extends Activity
  38. {
  39.     public static String IP = null;
  40.     private Button startbtn = null;
  41.     private Button stopbtn = null;
  42.     private Button okbtn = null;
  43.     private Button canclebtn = null;
  44.     private static TextView info_text = null;
  45.     private static EditText info_edit = null;
  46.     private static ContentResolver contentResolver = null;
  47.     @Override
  48.     protected void onCreate(Bundle savedInstanceState)
  49.     {
  50.         super.onCreate(savedInstanceState);
  51.         setContentView(R.layout.activity_main);
  52.         //启动服务按钮
  53.         startbtn = (Button)findViewById(R.id.startbtn);
  54.         //为按钮添加动作
  55.         startbtn.setOnClickListener(new ServiceListener());
  56.         //关闭服务按钮
  57.         startbtn = (Button)findViewById(R.id.stopbtn);
  58.         //为按钮添加动作
  59.         startbtn.setOnClickListener(new ServiceListener());
  60.         //确定按钮
  61.         okbtn = (Button)findViewById(R.id.ok);
  62.         okbtn.setOnClickListener(new ServiceListener());
  63.         //确定按钮
  64.         canclebtn = (Button)findViewById(R.id.modify);
  65.         canclebtn.setOnClickListener(new ServiceListener());
  66.         //获取textview
  67.         info_text = (TextView)findViewById(R.id.infoText);
  68.         info_edit = (EditText)findViewById(R.id.infoEdit);
  69.         info_text.setText("welcome!\n");
  70.         //获取contex
  71.         contentResolver = this.getContentResolver();
  72.     }
  73.     class ServiceListener implements OnClickListener
  74.     {

  75.         @Override
  76.         public void onClick(View v)
  77.         {
  78.             //启动tcp服务器
  79.             Intent intent = new Intent(MainActivity.this, listenerService.class);
  80.             switch(v.getId())
  81.             {
  82.                 //启动服务
  83.                 case R.id.startbtn:
  84.                     System.out.println("start service ");
  85.                     startService(intent);
  86.                     break;
  87.                 //关闭服务
  88.                 case R.id.stopbtn:
  89.                     System.out.println("stop service ");
  90.                     stopService(intent);
  91.                     break;
  92.                 case R.id.ok:
  93.                     //从editText获取IP
  94.                     IP = info_edit.getText().toString();
  95.                     break;
  96.                 case R.id.modify:
  97.                     //清空editText,清空ip
  98.                     info_edit.setText("");
  99.                     IP = null;
  100.                     break;
  101.                 default:
  102.                         break;
  103.             }
  104.             
  105.         }
  106.         
  107.     }
  108.     public static ContentResolver sendContentResolver()
  109.     {
  110.         return contentResolver;
  111.     }
  112.     
  113.     @Override
  114.     public boolean onCreateOptionsMenu(Menu menu)
  115.     {
  116.         // Inflate the menu; this adds items to the action bar if it is present.
  117.         getMenuInflater().inflate(R.menu.main, menu);
  118.         return true;
  119.     }

  120.     public static void setTextView(String string)
  121.     {
  122.         // TODO Auto-generated method stub
  123.         info_text.setText(string);
  124.     }
  125.     
  126.     
  127.     /*
  128.     class ServerThread extends Thread
  129.     {
  130.         ServerSocket serverSocket = null;
  131.         @Override
  132.         
  133.         public void run()
  134.         {
  135.             
  136.             // TODO Auto-generated method stub
  137.             super.run();
  138.             //申明一个SeverSocket对象
  139.             ServerSocket serverSocket = null;
  140.             try{
  141.                 //创建一个SeverSocket对象,监听80端口
  142.                 serverSocket = new ServerSocket(8080);
  143.                 //调用ServerSockrt的accept方法接受客户端发送的请求
  144.                 //如果客户端没有发送请求,accep函数会一直等待
  145.                 Socket socket = serverSocket.accept();
  146.                 //从socket中得到一个输入流
  147.                 InputStream inputStream = socket.getInputStream();
  148.                 byte buffer[] = new byte[1024*4];
  149.                 int temp = 0;
  150.                 //从inputstream中读取客户端发送的数据
  151.                 while((temp = inputStream.read(buffer)) != -1)
  152.                 {
  153.                     System.out.println(new String(buffer, 0, temp));
  154.                 }
  155.             }catch(IOException e){
  156.                 e.printStackTrace();
  157.             }
  158.             finally{
  159.                 try{
  160.                     serverSocket.close();
  161.                 }catch(IOException e){
  162.                     e.printStackTrace();
  163.                 }
  164.             }
  165.         }
  166.     }    */

  167. }



点击(此处)折叠或打开

  1. package com.example.incoming_number;

  2. import java.io.IOException;
  3. import java.io.OutputStream;
  4. import java.net.HttpURLConnection;
  5. import java.net.Socket;
  6. import java.net.URL;

  7. import com.example.incoming_number.inComingReceiver;
  8. import com.example.incoming_number.inComingReceiver.CustomPhoneStateListener;
  9. import com.example.incoming_number.inComingReceiver.HttpRequestThread;

  10. import android.app.Service;
  11. import android.content.BroadcastReceiver;
  12. import android.content.Context;
  13. import android.content.Intent;
  14. import android.content.IntentFilter;
  15. import android.os.Bundle;
  16. import android.os.IBinder;
  17. import android.telephony.PhoneStateListener;
  18. import android.telephony.SmsMessage;
  19. import android.telephony.TelephonyManager;
  20. import android.util.Log;

  21. public class listenerService extends Service
  22. {
  23.     //接收短信广播
  24.     IntentFilter filter_Message = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
  25.     //创建短信广播接收器
  26.     inComingReceiver iReceiver_Message = new inComingReceiver();
  27.     //接收短信广播
  28.     IntentFilter filter_Phone = new IntentFilter("android.intent.action.PHONE_STATE");
  29.     //创建来电广播接收器
  30.     inComingReceiver iReceiver_Phone = new inComingReceiver();
  31.     @Override
  32.     public IBinder onBind(Intent arg0)
  33.     {
  34.         // TODO Auto-generated method stub
  35.         return null;
  36.     }

  37.     @Override
  38.     public void onCreate()
  39.     {
  40.         // TODO Auto-generated method stub
  41.         System.out.println("create service ");
  42.         super.onCreate();
  43.     }


  44.     @Override
  45.     public int onStartCommand(Intent intent, int flags, int startId)
  46.     {
  47.         // TODO Auto-generated method stub
  48.         System.out.println("service is running");
  49.         //注册来电和短信广播接收器
  50.         registerReceiver(iReceiver_Message, filter_Message);
  51.         registerReceiver(iReceiver_Phone, filter_Phone);
  52.         
  53.         return super.onStartCommand(intent, flags, startId);
  54.     
  55.     }
  56.     
  57.     @Override
  58.     public void onDestroy()
  59.     {
  60.         // TODO Auto-generated method stub
  61.         super.onDestroy();
  62.         //注销广播接收器
  63.         unregisterReceiver(iReceiver_Message);
  64.         unregisterReceiver(iReceiver_Phone);
  65.         System.out.println("service is stop");
  66.     }
  67. }
  68. /*
  69.  * <receiver android:name="com.example.incoming_number.listenerService$iReceiver" >
  70.             <intent-filter>
  71.                 <action android:name="android.provider.Telephony.SMS_RECEIVED" />
  72.             </intent-filter>
  73.             <intent-filter>
  74.                 <action android:name="android.intent.action.PHONE_STATE" />
  75.             </intent-filter>
  76.         </receiver>
  77.  * */



点击(此处)折叠或打开

  1. package com.example.incoming_number;

  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.io.UnsupportedEncodingException;
  7. import java.net.HttpURLConnection;
  8. import java.net.MalformedURLException;
  9. import java.net.ServerSocket;
  10. import java.net.Socket;
  11. import java.net.URL;


  12. import android.content.BroadcastReceiver;
  13. import android.content.Context;
  14. import android.content.Intent;
  15. import android.os.Bundle;
  16. import android.telephony.PhoneStateListener;
  17. import android.telephony.SmsMessage;
  18. import android.telephony.TelephonyManager;
  19. import android.util.Log;
  20. import android.widget.TextView;

  21. /*当有电话进入时,系统会铜鼓哦广播的方式通知应用程序
  22. * BroadcastReceiver会自动接收系统广播,每次接收到广播就会调用    
  23. * onReceive方法
  24. */
  25. public class inComingReceiver extends BroadcastReceiver
  26. {

  27.     private static final String TAG = null;
  28.     private static String phoneNr = null;
  29.     private static String smsNr = null;
  30.     private static String contact_num = null;
  31.     private static String contact_name = null;
  32.     private static String info = null;
  33.     private static String http_info = null;
  34.     
  35.     public inComingReceiver()
  36.     {
  37.         
  38.     }
  39.     @Override
  40.     public void onReceive(Context context, Intent intent)
  41.     {
  42.         // TODO Auto-generated method stub

  43.         toPhoneNum toPhoneNr = new toPhoneNum();
  44.         getPhonePeopleActivity getpeople = new getPhonePeopleActivity();
  45.         
  46.         System.out.println("Recieve Message");
  47.         Log.i(TAG, "WE ARE INSIDE!!!!!!!!!!!");
  48.         
  49.         
  50.         //监听电话服务
  51.         TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
  52.         CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();
  53.         telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
  54.         
  55.         
  56.         //接收intent对象
  57.         Bundle bundle = intent.getExtras();
  58.         //获取来电号码
  59.         phoneNr= bundle.getString("incoming_number");
  60.         //将18810867651转换为1-881-086-7651
  61.         // phoneNr = toPhoneNr.makePhoneNum(phoneNr);
  62.         //通过号码得到联系人名字
  63.         // System.out.println("-------" +phoneNr+ "------");
  64.         info = "主人,来电话啦!";
  65.         contact_num = phoneNr;
  66.         contact_name = getpeople.getPeople(phoneNr);
  67.     // System.out.println(contact_num);
  68.     //    System.out.println(contact_name);
  69.         
  70.         
  71.         //如果不是来电,那就是短信
  72.         if(phoneNr == null)
  73.         {
  74.             //得到object类型数组
  75.             Object myOBJpdus[] = (Object[])bundle.get("pdus");
  76.             //得到smsmessage数组
  77.             SmsMessage smsMessage[] = new SmsMessage[myOBJpdus.length];
  78.             System.out.println(smsMessage.length);
  79.             //创建smsmessage对象
  80.             smsMessage[0] = SmsMessage.createFromPdu((byte[]) myOBJpdus[0]);
  81.             //得到消息的号码
  82.             smsNr = smsMessage[0].getDisplayOriginatingAddress();
  83.             
  84.             
  85.             //将18810867651转换为1-881-086-7651
  86.          //smsNr = toPhoneNr.makePhoneNum(smsNr);
  87.             //通过号码得到联系人名字
  88.             contact_num = smsNr;
  89.             contact_name = getpeople.getPeople(smsNr);
  90.     //        System.out.println(contact_num);
  91.     //        System.out.println(contact_name);
  92.             info = "主人,来短信啦";
  93.         }
  94.         
  95.         //启动http发送
  96.         new HttpRequestThread().start();
  97.      //更新TextView
  98.         MainActivity.setTextView("注意:\t" + info + "\n" + "姓名:\t" + contact_name + "\n" + "号码:\t" + contact_num + "\n" + "http:\t" + http_info);
  99.     
  100.     /*    for(int i = 0; i < myOBJpdus.length; i++)
  101.         {
  102.             //创建smsmessage对象
  103.             smsMessage[i] = SmsMessage.createFromPdu((byte[]) myOBJpdus[i]);
  104.             //得到消息的内容
  105.             System.out.println(smsMessage[i].getDisplayMessageBody());
  106.             //得到消息的号码
  107.             System.out.println(smsMessage[i].getDisplayOriginatingAddress());
  108.         }
  109.         //启动socket发送
  110.         new ClientThread().start(); */
  111.     }
  112.     
  113.     
  114.     public class CustomPhoneStateListener extends PhoneStateListener {
  115.         
  116.      private static final String TAG = "CustomPhoneStateListener";
  117.     
  118.      @Override
  119.      public void onCallStateChanged(int state, String incomingNumber){
  120.     
  121.      Log.v(TAG, "WE ARE INSIDE!!!!!!!!!!!");
  122.      Log.v(TAG, incomingNumber);
  123.      //检测来电的状态
  124.      switch(state){
  125.      case TelephonyManager.CALL_STATE_RINGING:
  126.      Log.d(TAG, "RINGING");
  127.      break;
  128.      case TelephonyManager.CALL_STATE_IDLE:
  129.      Log.d(TAG, "IDLE");
  130.      break;
  131.      case TelephonyManager.CALL_STATE_OFFHOOK:
  132.      Log.d(TAG, "OFFHOOK");
  133.      break;
  134.      }
  135.      }
  136.     }
  137.     
  138.     
  139.     //启动新的线程, 创建一个http链接,post数据
  140.     public class HttpRequestThread extends Thread
  141.     {
  142.         public void run()
  143.         {
  144.             // TODO Auto-generated method stub
  145.             super.run();
  146.             String path = MainActivity.IP;
  147.             System.out.println("IP is:" + path);
  148.             System.out.println("http server is running");
  149.             try
  150.             {
  151.                 sendString(path, info);
  152.             } catch (Exception e1)
  153.             {
  154.                 // TODO Auto-generated catch block
  155.                 e1.printStackTrace();
  156.             }
  157.             try
  158.             {
  159.                 //发送号码
  160.                 sendString(path, "contact_num is :" + contact_num);
  161.             } catch (Exception e)
  162.             {
  163.                 // TODO Auto-generated catch block
  164.                 e.printStackTrace();
  165.             }
  166.             try
  167.             {
  168.                 //发送名字
  169.                 sendString(path, "contact_name is:" + contact_name);
  170.             } catch (Exception e)
  171.             {
  172.                 // TODO Auto-generated catch block
  173.                 e.printStackTrace();
  174.             }
  175.             System.out.println("------- "+ info + "------");
  176.             System.out.println("------- "+ contact_num + "------");
  177.             System.out.println("------- "+ contact_name + "------");
  178.             System.out.println("http server is over");
  179.         }
  180.     }
  181.     
  182.     //通过post方法向http发送数据
  183.     public boolean sendString(String path, String str) throws Exception
  184.     {
  185.      byte[] data = str.getBytes();
  186.      URL url = new URL(path);
  187.      HttpURLConnection conn = (HttpURLConnection)url.openConnection();
  188.         conn.setRequestMethod("POST");
  189.         conn.setConnectTimeout(5 * 1000);
  190.        //如果通过post提交数据,必须设置允许对外输出数据
  191.         conn.setDoOutput(true);
  192.      conn.setRequestProperty("Content-Type", "String; charset=UTF-8");
  193.      conn.setRequestProperty("Content-Length", String.valueOf(data.length));
  194.      OutputStream outStream = conn.getOutputStream();
  195.      outStream.write(data);
  196.      outStream.flush();
  197.      outStream.close();
  198.      if(conn.getResponseCode()==200)
  199.      {
  200.          System.out.println("http is running over");
  201.          http_info = "Data is send!";
  202.      return true;
  203.      }
  204.      System.out.println("http is running wrong");
  205.      http_info = "http post is wrong";
  206.      return false;
  207.     }    
  208.     
  209.     
  210.     /*
  211.     //创建TCP客户端
  212.     class ClientThread extends Thread
  213.     {
  214.         //InputStream is = new ByteArrayInputStream(string.getBytes());
  215.         @Override
  216.         public void run()
  217.         {
  218.             // TODO Auto-generated method stub
  219.             super.run();
  220.             System.out.println("tcp cleint is running");
  221.             try{
  222.                 //创建一个socket,指定服务器端的ip地址和端口,
  223.                 Socket socket = new Socket("192.168.1.116", 7654);
  224.                 //从sicket获取一个outputstream
  225.                 OutputStream outputStream = socket.getOutputStream();
  226.                 byte buffer[] = smsNr.getBytes();
  227.                 int temp = buffer.length;
  228.                 //将buffer的内容写入outputstream
  229.                 outputStream.write(buffer, 0, temp);
  230.                 outputStream.flush();
  231.             }catch    (IOException e){
  232.                 e.printStackTrace();
  233.                 
  234.                 System.out.println("tcp cleint is running over");
  235.             }
  236.         }
  237.     }
  238.     */
  239. }


点击(此处)折叠或打开

  1. package com.example.incoming_number;

  2. import android.app.Activity;
  3. import android.content.ContentResolver;
  4. import android.database.Cursor;
  5. import android.provider.ContactsContract;
  6. import android.util.Log;

  7. //通过电话号码获取姓名
  8. public class getPhonePeopleActivity
  9. {
  10.     private static final String TAG = null;
  11.     String str = "未知号码";
  12.     String name = null;
  13.     public String getPeople(String phoneNr) {
  14.       /* String[] projection = { android.provider.ContactsContract.Contacts.DISPLAY_NAME,
  15.                 };
  16.   
  17.         Log.d(TAG, "getPeople ---------");
  18.         
  19.         ContentResolver contentResolver = MainActivity.sendContentResolver();
  20.      Cursor cursor = contentResolver.query(android.provider.ContactsContract.Contacts.CONTENT_URI,
  21.              projection,
  22.              android.provider.ContactsContract.Contacts.HAS_PHONE_NUMBER + " = '" + phoneNr + "'",
  23.              null, null);
  24.      cursor.getCount();
  25.      while(cursor.moveToNext()) {
  26.      System.out.println("NUM:"+cursor.getString(cursor.getColumnIndex(android.provider.ContactsContract.Contacts._ID)));
  27.      System.out.println("NAME:"+cursor.getString(cursor.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME)));
  28.      }
  29.     // cursor.close(); */
  30.           
  31.         String[] projection = { ContactsContract.PhoneLookup.DISPLAY_NAME,
  32.                 ContactsContract.CommonDataKinds.Phone.NUMBER};

  33.         Log.d(TAG, "getPeople ---------");
  34.         ContentResolver contentResolver = MainActivity.sendContentResolver();
  35.         // 将自己添加到 msPeers 中
  36.         Cursor cursor = contentResolver.query(
  37.         ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
  38.         projection, // Which columns to return.
  39.         ContactsContract.CommonDataKinds.Phone.NUMBER + " = '" + phoneNr + "'", // WHERE clause.
  40.         null, // WHERE clause value substitution
  41.         null); // Sort order
  42.         
  43.         if( cursor == null ) {
  44.             Log.d(TAG, "getPeople null");
  45.             return str;
  46.         }
  47.         Log.d(TAG, "getPeople cursor.getCount() = " + cursor.getCount());
  48.         //未找到匹配的联系人,那么就是未知号码
  49.         if(cursor.getCount() == 0)
  50.         {
  51.             return str;
  52.         }
  53.         //System.out.println("phoneNum is:" + phoneNr);
  54.         for( int i = 0; i < cursor.getCount(); i++ )
  55.         {
  56.             cursor.moveToPosition(i);
  57.               
  58.             // 取得联系人名字
  59.             int nameFieldColumnIndex = cursor.getColumnIndex(android.provider.ContactsContract.Contacts.DISPLAY_NAME);
  60.             name = cursor.getString(nameFieldColumnIndex);
  61.             Log.i("Contacts", "" + name + " .... " + nameFieldColumnIndex); // 这里提示 force close
  62.             System.out.println("name is:" + name);
  63.         }
  64.         return name;
  65.     }
  66. }
  67. //ContactsContract.CommonDataKinds.Phone.NUMBER + " = '" + phoneNr + "'", // WHERE clause.
  68. //android.provider.ContactsContract.Contacts.HAS_PHONE_NUMBER + " = '" + phoneNr + "'"


点击(此处)折叠或打开

  1. package com.example.incoming_number;

  2. import java.io.UnsupportedEncodingException;

  3. /*
  4.  * 将号码18810867651转变成模拟器的格式1-881-086-7651
  5.  * 这个类将依据手机的内号码的存放格式而定
  6.  * */
  7. public class toPhoneNum
  8. {
  9.     
  10.     private byte b[] =    null;
  11.     private byte c[] =    new byte[14];
  12.     private String phoneNr = null;;
  13.     public String makePhoneNum(String str)
  14.     {
  15.         try
  16.         {
  17.             b = str.getBytes("ISO-8859-1");
  18.         } catch (UnsupportedEncodingException e1)
  19.         {
  20.             // TODO Auto-generated catch block
  21.             e1.printStackTrace();
  22.         }
  23.         c[0] = b[0];
  24.         c[1] = '-';
  25.         c[2] = b[1];
  26.         c[3] = b[2];
  27.         c[4] = b[3];
  28.         c[5] = '-';
  29.         c[6] = b[4];
  30.         c[7] = b[5];
  31.         c[8] = b[6];
  32.         c[9] = '-';
  33.         c[10] = b[7];
  34.         c[11] = b[8];
  35.         c[12] = b[9];
  36.         c[13] = b[10];
  37.         try
  38.         {
  39.             phoneNr = new String(c,"ISO-8859-1");
  40.         } catch (UnsupportedEncodingException e)
  41.         {
  42.             // TODO Auto-generated catch block
  43.             e.printStackTrace();
  44.         }
  45.         return phoneNr;
  46.     }
  47. }




点击(此处)折叠或打开

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:tools="http://schemas.android.com/tools"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent"
  5.     android:paddingBottom="@dimen/activity_vertical_margin"
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"
  7.     android:paddingRight="@dimen/activity_horizontal_margin"
  8.     android:paddingTop="@dimen/activity_vertical_margin"
  9.     tools:context=".MainActivity" >

  10. <Button
  11.     android:id = "@+id/startbtn"
  12.     android:layout_height="wrap_content"
  13.     android:layout_width="fill_parent"
  14.     android:text="开启监听服务"
  15.     />
  16. <Button
  17.     android:id = "@+id/stopbtn"
  18.     android:layout_below="@+id/startbtn"
  19.     android:layout_height="wrap_content"
  20.     android:layout_width="fill_parent"
  21.     android:text="关闭监听服务"
  22.     />
  23. <EditText
  24.     android:id="@+id/infoEdit"
  25.     android:hint="请输入http服务器的IP地址"
  26.     android:layout_width="fill_parent"
  27.     android:layout_height="50dp"
  28.     android:textSize="20sp"
  29.     android:textColor="#00ff00"
  30.     android:inputType="none"
  31.     android:layout_below="@+id/stopbtn" />

  32. <TextView
  33.     android:id="@+id/infoText"
  34.     android:layout_width="fill_parent"
  35.     android:layout_height="100dp"
  36.     android:layout_alignRight="@+id/infoEdit"
  37.     android:layout_below="@+id/ok"
  38.     android:textColor="#00ff00"
  39.     android:textSize="20sp" />

  40. <Button
  41.     android:id="@+id/ok"
  42.     android:layout_width="wrap_content"
  43.     android:layout_height="wrap_content"
  44.     android:layout_alignLeft="@+id/infoText"
  45.     android:layout_below="@+id/infoEdit"
  46.     android:text="确定" />

  47. <Button
  48.     android:id="@+id/modify"
  49.     android:layout_width="wrap_content"
  50.     android:layout_height="wrap_content"
  51.     android:layout_alignLeft="@+id/infoEdit"
  52.     android:layout_below="@+id/infoEdit"
  53.     android:layout_marginLeft="68dp"
  54.     android:text="修改" />

  55. </RelativeLayout>


点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.     package="com.example.incoming_number"
  4.     android:versionCode="1"
  5.     android:versionName="1.0" >

  6.     <uses-sdk
  7.         android:minSdkVersion="8"
  8.         android:targetSdkVersion="18" />

  9.     <application
  10.         android:allowBackup="true"
  11.         android:icon="@drawable/ic_launcher"
  12.         android:label="@string/app_name"
  13.         android:debuggable="true"
  14.         android:theme="@style/AppTheme" >
  15.         <activity
  16.             android:name="com.example.incoming_number.MainActivity"
  17.             android:label="@string/app_name" >
  18.             <intent-filter>
  19.                 <action android:name="android.intent.action.MAIN" />

  20.                 <category android:name="android.intent.category.LAUNCHER" />
  21.             </intent-filter>
  22.         </activity>
  23.         <service android:name = "com.example.incoming_number.listenerService"/>

  24.     </application>
  25.     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  26.     <uses-permission android:name="android.permission.RECEIVE_SMS" />
  27.     <uses-permission android:name="android.permission.INTERNET"/>
  28.     <uses-permission android:name="android.permission.READ_CONTACTS"/>
  29. </manifest>