<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      android 自動撥打電話 掛斷電話代碼

      頁面布局文件代碼  (  res下面的layout下面的activity_main.xml代碼 )

       

      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.u.phone.MainActivity" >

      <TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:layout_marginLeft="18dp"
      android:layout_marginTop="28dp"
      android:text="手機號碼:" />

      <EditText
      android:id="@+id/phonetext"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginLeft="90dp"
      android:layout_marginTop="16dp"
      android:text=""/>

      <TextView
      android:id="@+id/textView2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:layout_marginLeft="18dp"
      android:layout_marginTop="70dp"
      android:text="呼叫幾秒:" />

      <EditText
      android:id="@+id/shijiantext"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginLeft="90dp"
      android:layout_marginTop="60dp"
      android:text="5"/>

      <Button
      android:id="@+id/submitbutton"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@+id/textView2"
      android:layout_below="@+id/textView2"
      android:layout_marginLeft="30dp"
      android:layout_marginTop="53dp"
      android:text="撥打電話" />

      <Button
      android:id="@+id/clearcall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@+id/textView2"
      android:layout_below="@+id/textView2"
      android:layout_marginLeft="160dp"
      android:layout_marginTop="53dp"
      android:text="停止呼叫" />

      </RelativeLayout>

       

      MainActivity.java代碼  ( src下面的com.u.phone 下面的 MainActivity.java )

       

      package com.u.phone;

      import android.support.v7.app.ActionBarActivity;
      import android.os.Bundle;
      import android.view.Menu;
      import android.view.MenuItem;
      import android.widget.Button;
      import android.widget.EditText;
      import android.view.View;
      import android.content.Intent;
      import android.net.Uri;
      import com.android.internal.telephony.ITelephony;
      import android.telephony.TelephonyManager;
      import android.content.Context;
      import java.lang.reflect.Method;
      import android.view.View.OnClickListener;


      public class MainActivity extends ActionBarActivity {
      private Button start=null;
      private Button stop =null;
      private EditText photoNo=null;
      private boolean runnable=true;
      private boolean endCall=false;
      private String telePhotoNo=null;
      private EditText sjText=null;
      private String sjNum=null;
      ITelephony iPhoney=null;
      //private TelephonyManager;
      Thread t=null;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      //取得資源
      start=(Button)findViewById(R.id.submitbutton);
      stop=(Button)findViewById(R.id.clearcall);
      photoNo=(EditText)findViewById(R.id.phonetext);
      sjText=(EditText)findViewById(R.id.shijiantext);
      final TelephonyManager tm=(TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
      iPhoney=getITelephony(this);//獲取電話實例
      //增加事件響應
      start.setOnClickListener(new OnClickListener(){
      @Override
      public void onClick(View v) {
      telePhotoNo=photoNo.getText().toString().trim();
      sjNum=sjText.getText().toString().trim();
      //System.out.println(telePhotoNo);
      t.start();
      }
      });
      //增加事件響應
      stop.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
      runnable=false;
      System.exit(0);
      // finish();
      }
      });
      //線程
      t=new Thread(new Runnable() {

      @Override
      public void run() {
      try {
      while(runnable){

      Thread.sleep(2000);//延時5s
      int state=tm.getCallState();
      if(state==TelephonyManager.CALL_STATE_IDLE){
      Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+telePhotoNo));
      startActivity(intent);
      }
      if(state==TelephonyManager.CALL_STATE_OFFHOOK){
      Thread.sleep(Integer.parseInt(sjNum)*1000);//延時10s
      endCall= iPhoney.endCall();
      //System.out.println("是否成功掛斷:"+endCall);
      }


      }
      } catch (Exception e)
      {
      e.printStackTrace();
      }
      }
      });


      }


      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
      }

      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
      return true;
      }
      return super.onOptionsItemSelected(item);
      }
      /**
      * 通過反射得到實例
      * @param context
      * @return
      */
      private static ITelephony getITelephony(Context context) {
      TelephonyManager mTelephonyManager = (TelephonyManager) context
      .getSystemService(TELEPHONY_SERVICE);
      Class<TelephonyManager> c = TelephonyManager.class;
      Method getITelephonyMethod = null;
      try {
      getITelephonyMethod = c.getDeclaredMethod("getITelephony",
      (Class[]) null); // 獲取聲明的方法
      getITelephonyMethod.setAccessible(true);
      } catch (SecurityException e) {
      e.printStackTrace();
      } catch (NoSuchMethodException e) {
      e.printStackTrace();
      }
      ITelephony iTelephony=null;
      try {
      iTelephony = (ITelephony) getITelephonyMethod.invoke(
      mTelephonyManager, (Object[]) null); // 獲取實例
      return iTelephony;
      } catch (Exception e) {
      e.printStackTrace();
      }
      return iTelephony;
      }


      }

       

       

      電話權限: AndroidManifest.xml里加入下面2行權限代碼

      <uses-permission android:name="android.permission.CALL_PHONE"/>
      <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

       

      posted on 2016-07-13 07:36  八度空間  閱讀(2010)  評論(0)    收藏  舉報

      導航

      主站蜘蛛池模板: 国产97人人超碰CAO蜜芽PROM | 国产精品中文一区二区| 午夜福利激情一区二区三区 | 亚洲国产精品男人的天堂| 97人人添人人澡人人澡人人澡| 亚洲色拍拍噜噜噜最新网站| 国产一卡2卡三卡4卡免费网站| 四虎影视一区二区精品| 亚洲欧美国产精品久久久久久久| 夜色福利站WWW国产在线视频| 国产乱码日韩精品一区二区| 在线观看的网站| 国产精品久久国产精麻豆| 国产色无码专区在线观看 | 无码人妻丰满熟妇区五十路在线| 被黑人巨大一区二区三区| 国产欧美另类久久久精品丝瓜| 无码人妻av免费一区二区三区| 亚洲电影在线观看| 亚洲国产精品综合一区二区| av中文字幕在线二区| 永久免费无码成人网站| 国产亚洲欧洲av综合一区二区三区| 人妻少妇无码精品专区| 亚洲欧洲日产国码AV天堂偷窥| japanese人妻中文字幕| 深夜福利啪啪片| 久久精品国产88精品久久| 日韩av无码中文无码电影| 九九热精品在线视频观看| 蜜芽久久人人超碰爱香蕉| 遂平县| 欧美粗大猛烈老熟妇| 女人扒开的小泬高潮喷小| 无码专区 人妻系列 在线| 亚洲日韩国产精品第一页一区| 国产精品美女www爽爽爽视频| 加勒比中文字幕无码一区| 久久精品国产99国产精品澳门| 人妻久久久一区二区三区| 丰满的熟妇岳中文字幕|