6
A
回答
15
让我们在3个步骤实现此解决方案:
一个。这个类定义或接收器:
这是你的主类:
package com.sample;
import java.lang.reflect.Method;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
import com.android.internal.telephony.*;
public class main extends BroadcastReceiver {
private static final String TAG = null;
String incommingNumber;
String incno1= "9916090941";
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
try {
// Java reflection to gain access to TelephonyManager's
// ITelephony getter
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Log.v(TAG, "Get getTeleService...");
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
Bundle b = intent.getExtras();
incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.v(TAG,incommingNumber);
Log.v(TAG,incno1);
if (incommingNumber.equals(incno1))
{
telephonyService = (ITelephony) m.invoke(tm);
telephonyService.silenceRinger();
telephonyService.endCall();
Log.v(TAG,"BYE BYE BYE");
}
else{
telephonyService.answerRingingCall();
Log.v(TAG,"HELLO HELLO HELLO");
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG,
"FATAL ERROR: could not connect to telephony subsystem");
Log.e(TAG, "Exception object: " + e);
}
}
}
湾清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name=".main">
<intent-filter android:priority="100" >
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>
c。定义电话AIDL,下com.android.internal.telephony
package com.android.internal.telephony;
interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
MH:只能在模拟器为我工作,而不是在真实设备...的Android 2.3以上的所有设备都需要root权限或安装作为一个系统应用能够使用权限android.permission.MODIFY_PHONE_STATE
。
+0
有没有办法将呼叫发送到语音邮件? – powder366 2014-02-26 18:06:55
+1
我复制并粘贴这些文件,但它不起作用! 我删除了此权限 – 2014-09-09 07:42:04
相关问题
- 1. 如何在android中以编程方式拒绝呼叫
- 2. 以编程方式拒绝权限 - Android
- 3. C#Outlook - 呼叫被拒绝的呼叫
- 4. SipAudioCall.endCall不拒绝呼叫
- 5. 以编程方式断开Android Marshmallow版本中的呼叫
- 6. 如何在Android L中以编程方式打开传入呼叫的扬声器?
- 7. Yammer以编程方式拒绝请求
- 8. IOS以编程方式拒绝来电?
- 9. 以编程方式阻止黑莓上的传出呼叫
- 10. 如何以编程方式拒绝编辑页眉和页脚?
- 11. 如何在android中查找可以处理传入呼叫的应用程序?
- 12. 如何通过编程方式拒绝通话android
- 13. 以编程方式在Python中拒绝/ nohup
- 14. 导出到Excel呼叫被拒绝
- 15. 呼叫被callee拒绝PowerPoint自动
- 16. 在VOIP呼叫期间以编程方式启用扬声器
- 17. Windows程序以编程方式捕获电话呼叫数据?
- 18. 如何在Android中存储传入呼叫
- 19. 如何在android中以编程方式创建时传递AttributeSet
- 20. 星号,呼叫下一个座席(如果有的话)将拒绝呼叫
- 21. 以编程方式更改呼叫类型
- 22. 以编程方式将服务呼叫添加到SharePoint呼叫中心应用程序
- 23. 是否可以使用objective-c自动拒绝呼叫?
- 24. iPhone如何以编程方式处理短信/呼叫警报通知
- 25. 以编程方式创建SPAlert时访问被拒绝错误
- 26. 以编程方式在android
- 27. 如何处理传入呼叫通知的中断挂断呼叫
- 28. 得到呼叫由被叫例外VSTO(Word应用程序)拒绝
- 29. 如何在android中阻止呼叫
- 30. iphone编程 - 如何记录呼叫
http://stackoverflow.com/questions/1083527/how-to-block-calls-in-android – B00MER 2010-09-28 04:22:30