• using Broadcast Receivers to listen outgoing call in android note


    1.reference url

    http://www.krvarma.com/posts/android/detecting-incoming-and-outgoing-calls-in-android/

    2.add permission in Manifest.xml

    View Code
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package
    ="com.guc.android"
    android:versionCode
    ="1"
    android:versionName
    ="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
    <activity android:name=".Welcome"
    android:label
    ="@string/app_name">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    <activity android:name=".Doctor"
    android:label
    ="医生信息"
    android:theme
    ="@android:style/Theme.Light" >
    </activity>

    <activity android:name=".HomeArchive"
    android:label
    ="家庭档案信息" >
    </activity>

    <receiver android:name="com.guc.comm.GucOutgoingCallReceiver">
    <intent-filter>
    <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
    </intent-filter>
    </receiver>
    </application>
    </manifest>

    3.add class OutgongReceiver extends BroadcastReceiver

    View Code
    package com.guc.comm;

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;

    public class GucOutgoingCallReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Bundle bundle = intent.getExtras();
    if (null == bundle)
    return;
    // String
    // outgoingNumber=intent.getStringExtra(Intent.ACTION_NEW_OUTGOING_CALL);
    String phoneNubmer = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
    Log.i(
    "OutgoingCallReceiver", phoneNubmer);
    Log.i(
    "OutgoingCallReceiver", bundle.toString());
    //
    }
    }

    4.save outgoing phone number when dial

    View Code
    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    Intent dialIntent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:13724560911"));
    startActivity(dialIntent);

    // TelephonyManager tm = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
    // PhoneStateListener phoneListener=new PhoneStateListener();
    // //phoneListener.onCallStateChanged(state, incomingNumber)
    // tm.listen(phoneListener, phoneListener.LISTEN_CALL_STATE);
    }

  • 相关阅读:
    redis集群学习
    Java -cp 命令行引用多个jar包的简单写法(Windows、Linux
    内部类的继承
    NIO的epoll空轮询bug
    linux下socket的连接队列的 backlog的分析
    jQuery animate动画 stop()方法详解~
    jQuery插件之Cookie插件使用方法~
    jQuery中 pageX,clientX,offsetX,layerX的区别
    JavaScript 中一些概念理解 :clientX、clientY、offsetX、offsetY、screenX、screenY
    jQuery $.fn 方法扩展~
  • 原文地址:https://www.cnblogs.com/tuolin/p/2031158.html
Copyright © 2020-2023  润新知