我需要访问com.android.internal.telephony.Call。
执行此操作:
// Initialize the telephony framework
PhoneFactory.makeDefaultPhones (this);
// Get the default phone
Phone phone = PhoneFactory.getDefaultPhone ();
CallManager mCM = CallManager.getInstance ();
mCM.registerPhone (phone);
Call call = mCM.getFirstActiveBgCall();
但是不能扩展到初始化框架。
帮我初始化调用。
我需要读取呼叫的状态,如:空闲、活动、等待、拨号、告警、来电、等待、断开、断开。
发布于 2012-06-10 17:19:16
您需要使用PhoneStateListener,它将为您提供让您的应用程序侦听电话呼叫的不同状态的工具。您需要将<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
放入清单文件中
发布于 2013-05-15 16:15:37
您可以,但有一个关键要求:应用程序必须在系统级签名,这意味着您是制造商。
下面是如何编写一个服务,该服务将为前台呼叫状态中的每个更改广播意图。
/*
* This implementation uses the com.android.internal.telephony package: you have
* to extract the framework classes .jar file from the platform (or the
* emulator) to compile this code. Also, add the jar file to the external
* libraries in the Java Build Path/libraries of the android project. </p>
*
* The jar file must match the android version you are building the application
* for. Because this implementation is using the internal packages it cannot be
* guaranteed to operate on later versions of android.
*/
public class CallStateNotificationService extends Service {
private static final String LOG_TAG = CallStateNotificationService.class.getSimpleName();
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
if (msg.what == 101) {
CallManager callManager = CallManager.getInstance();
Call.State state = callManager.getActiveFgCallState();
Intent intent = new Intent(PhoneIntents.ACTION_PRECISE_CALL_STATE);
intent.putExtra(PhoneIntents.PRECISE_CALL_STATE, state.name());
Context context = getApplicationContext();
context.sendBroadcast(intent);
}
}
};
@Override
public void onCreate() {
super.onCreate();
try {
CallManager callManager = CallManager.getInstance();
if (callManager != null) {
callManager.registerForPreciseCallStateChanged(mHandler, 101, null);
} else {
Log.w(LOG_TAG, "Can't resolve CallManager reference"); //$NON-NLS-1$
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onDestroy() {
super.onDestroy();
CallManager callManager = CallManager.getInstance();
if (callManager != null) {
callManager.unregisterForPreciseCallStateChanged(mHandler);
} else {
Log.w(LOG_TAG, "Can't resolve CallManager reference"); //$NON-NLS-1$
}
}
下面是自定义广播意图的定义。
/** Intent action and extra argument names for CallStateNotificationService */
public final class PhoneIntents {
public static final String ACTION_PRECISE_CALL_STATE = "com.myorg.myapp.CALL_STATE";
public static final String PRECISE_CALL_STATE = "precise_call_state";
}
要编译和链接这段代码,您当然需要将程序构建为android发行版本身的一部分,或者通过Internet上其他地方解释的方法导入类框架。
所有这些目前都在一个正在生产的应用程序中。
https://stackoverflow.com/questions/10967553
复制相似问题