• 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);
    }

  • 相关阅读:
    [Windows Server 2012] 安装PHP+MySQL方法
    [Windows Server 2012] 安装IIS8.5及FTP
    [Windows Server 2012] IIS自带FTP配置方法
    护卫神,服务器安全专家!
    ie9 UpdateModel失败
    打包自己的nuget时,设置安装此nuget改写web.config
    Roslyn 1.2.0.0 的改变
    用自定义routes把不同的querystring名对应到action同一个参数上
    JetBrains dotCover 2.0 破解研究(注册机)
    mvc4 中的 AuthorizeAttribute
  • 原文地址:https://www.cnblogs.com/tuolin/p/2031158.html
Copyright © 2020-2023  润新知