zoukankan      html  css  js  c++  java
  • 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);
    }

  • 相关阅读:
    py-day1-2 python的循环语句
    B/S和C/S结构的区别
    php get_magic_quotes_gpc() addslashes()
    SqlHelper数据库访问类
    随滚动条滚动的居中div
    有关Repeater的事件
    Repeater的ItemCommand事件和ItemCreated事件,高手请跳过~
    温故而知新之数据库的分离和附加…高手请跳过….
    自己做的一个小功能~
    php什么是变量的数据类型
  • 原文地址:https://www.cnblogs.com/tuolin/p/2031158.html
Copyright © 2011-2022 走看看