- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以拦截来电和去电。我的问题是它在 2.3.x 版本中不起作用
这里是我的代码:
public class PhoneCallReceiver extends BroadcastReceiver {
/**
* Call back which fires off when the phone changes state.
*/
@Override
public void onReceive(Context context, Intent intent) {
//TODO
//===========
//here i need to chack the number
// Bundle b = intent.getExtras();
// String incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
// Additional Step
// Check whether this number matches with your defined Block List
// If yes, Reject the Call
//===========
/* examine the state of the phone that caused this receiver to fire off */
String phone_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (phone_state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
// if (context.getSharedPreferences(Hc.PREFSNAME,0).getBoolean(Hc.PREF_CALL_ANSWER_TOOLS_KEY, true))
// {
logMe("Phone Ringing: the phone is ringing, scheduling creation call answer screen activity");
Intent i = new Intent(context, CallAnswerIntentService.class);
i.putExtra("delay", 100L);
context.startService(i);
logMe("Phone Ringing: started, time to go back to listening");
// } else {
// logMe("Phone Ringing: Call Answer tools disabled by user");
// }
}
if (phone_state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
{
// if (context.getSharedPreferences(Hc.PREFSNAME,0).getBoolean(Hc.PREF_SCREEN_GUARD_TOOLS_KEY, true))
// {
//TODO
Intent i = new Intent(context,InCallScreenGuardService.class);
i.putExtra("delay", 100L);
logMe("Phone Offhook: starting screen guard service");
context.startService(i);
// } else {
// logMe("Phone Offhook: In-Call Screen Guard disabled by user");
// }
}
if (phone_state.equals(TelephonyManager.EXTRA_STATE_IDLE))
{
// if (context.getSharedPreferences(Hc.PREFSNAME,0).getBoolean(Hc.PREF_SCREEN_GUARD_TOOLS_KEY, true))
// {
//TODO
Intent i = new Intent(context,InCallScreenGuardService.class);
logMe("Phone Idle: stopping screen guard service");
context.stopService(i);
// } else {
// logMe("Phone Idle: In-Call Screen Guard disabled by user");
// }
}
return;
}
此发送 Intent 到服务和服务发送 Intent 到以下 Activity :
public class CallAnswerActivity extends Activity {
/**
* whether or not to use the AIDL technique or
* the HEADSET_HOOK/package restart techniques
*/
private static final boolean USE_ITELEPHONY = true;
/**
* internal phone state broadcast receiver
*/
protected BroadcastReceiver r;
/**
* TelephonyManager instance used by this activity
*/
private TelephonyManager tm;
/**
* AIDL access to the telephony service process
*/
private com.android.internal.telephony.ITelephony telephonyService;
// ------------------------------------------------------------------------
// primary life cycle call backs
// ------------------------------------------------------------------------
/**
* main() :)
*/
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
debugLog("onCreate called");
setContentView(R.layout.callanswerscreen);
// grab an instance of telephony manager
tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
// connect to the underlying Android telephony system
if (USE_ITELEPHONY)
connectToTelephonyService();
// turn our idle phone state receiver on
registerReciever();
// touch screen return button
Button returnToCallScreen = (Button) findViewById(R.id.returnToCallScreen);
returnToCallScreen.setOnClickListener(new ReturnButtonOnClickListener());
// touch screen reject/ignore call button
Button rejectCall = (Button) findViewById(R.id.rejectCallButton);
// if (getSharedPreferences(Hc.PREFSNAME,0).getBoolean(Hc.PREF_ALLOW_REJECT_KEY, true))
rejectCall.setOnLongClickListener(new RejectCallOnLongClickListener());
// else
// rejectCall.setVisibility(View.GONE);
// touch screen answer button
Button answerButton = (Button) findViewById(R.id.answerCallButton);
// if (getSharedPreferences(Hc.PREFSNAME,0).getBoolean(Hc.PREF_ANSWER_WITH_BUTTON_KEY, true))
answerButton.setOnLongClickListener(new AnswerCallOnLongClickListener());
// else
// answerButton.setVisibility(View.GONE);
}
/**
* (re)register phone state receiver on resume, exit if the phone is idle
*/
@Override protected void onResume() {
super.onResume();
registerReciever();
if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
debugLog("phone is idle, stopping.");
exitCleanly();
}
}
/**
* unregister phone state receiver, schedule restart if not exiting at the users request
*/
@Override protected void onPause() {
super.onPause();
unHookReceiver();
if (!isFinishing())
{
debugLog("system forced pause occured, scheduling delayed restart");
Intent i = new Intent(getApplicationContext(), CallAnswerIntentService.class);
i.putExtra("delay", Hc.RESTART_DELAY);
startService(i);
}
}
// ------------------------------------------------------------------------
// Input event handler call backs
// ------------------------------------------------------------------------
/**
* Track ball press event handler that will answer a call
*/
@Override public boolean onTrackballEvent(MotionEvent event) {
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE: return true;
case MotionEvent.ACTION_DOWN: answerCall(); return true;
default: debugLog("trackball event: "+event);
}
return super.dispatchTrackballEvent(event);
}
/**
* Camera button press event handler that will answer a call
*/
@Override public boolean dispatchKeyEvent(KeyEvent event) {
switch (event.getKeyCode())
{
case KeyEvent.KEYCODE_FOCUS: return true;
case KeyEvent.KEYCODE_CAMERA: answerCall(); return true;
default: debugLog("Unknown key event: "+event);
}
return super.dispatchKeyEvent(event);
}
/**
* Return button click listener will exit back to the
* phones stock answer call application.
*/
private class ReturnButtonOnClickListener implements OnClickListener {
public void onClick(View v) {
debugLog("returnToCallScreen onClick event");
exitCleanly();
}
}
/**
* Reject button long click listener will reject the
* incoming call.
*/
private class RejectCallOnLongClickListener implements OnLongClickListener {
public boolean onLongClick(View v){
debugLog("touch screen ignore call button onClick event");
ignoreCall();
exitCleanly();
return true;
}
}
/**
* Answer button long click listener will answer the
* incoming call.
*/
private class AnswerCallOnLongClickListener implements OnLongClickListener {
public boolean onLongClick(View v){
debugLog("touch screen answer button onClick event");
answerCall();
return true;
}
}
// ------------------------------------------------------------------------
// broadcast receivers
// ------------------------------------------------------------------------
/**
* register phone state receiver
*/
private void registerReciever() {
if (r != null) return;
r = new BroadcastReceiver() {
@Override
public void onReceive(Context c, Intent i) {
String phone_state = i.getStringExtra(TelephonyManager.EXTRA_STATE);
if (!phone_state.equals(TelephonyManager.EXTRA_STATE_RINGING))
{
debugLog("received "+phone_state+", time to go bye bye, thanks for playing!");
exitCleanly();
}
}
};
registerReceiver(r, new IntentFilter("android.intent.action.PHONE_STATE"));
}
/**
* unregister phone state receiver
*/
private void unHookReceiver() {
if (r != null)
{
unregisterReceiver(r);
r = null;
}
}
// ------------------------------------------------------------------------
// application methods
// ------------------------------------------------------------------------
/**
* get an instance of ITelephony to talk handle calls with
*/
@SuppressWarnings("unchecked") private void connectToTelephonyService() {
try
{
// "cheat" with Java reflection to gain access to TelephonyManager's ITelephony getter
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (com.android.internal.telephony.ITelephony) m.invoke(tm);
} catch (Exception e) {
e.printStackTrace();
debugLog("FATAL ERROR: could not connect to telephony subsystem");
debugLog("Exception object: "+e);
finish();
}
}
//
// answer call
//
/**
* answer incoming calls
*/
private void answerCall() {
if (USE_ITELEPHONY)
try {
answerCallAidl();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else
answerCallHeadsetHook();
exitCleanly();
}
/**
* ACTION_MEDIA_BUTTON broadcast technique for answering the phone
*/
private void answerCallHeadsetHook() {
KeyEvent headsetHook = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK);
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, headsetHook);
sendOrderedBroadcast(mediaButtonIntent, null);
}
/**
* AIDL/ITelephony technique for answering the phone
*/
private void answerCallAidl() throws RemoteException {
telephonyService.silenceRinger();
telephonyService.answerRingingCall();
}
//
// ignore call
//
/**
* ignore incoming calls
*/
private void ignoreCall() {
if (USE_ITELEPHONY)
try {
ignoreCallAidl();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else
ignoreCallPackageRestart();
}
/**
* package restart technique for ignoring calls
*/
private void ignoreCallPackageRestart() {
ActivityManager am = (ActivityManager)getSystemService(ACTIVITY_SERVICE);
am.restartPackage("com.android.providers.telephony");
am.restartPackage("com.android.phone");
}
/**
* AIDL/ITelephony technique for ignoring calls
*/
private void ignoreCallAidl() throws RemoteException {
telephonyService.silenceRinger();
telephonyService.endCall();
}
/**
* cleanup and exit routine
*/
private void exitCleanly() {
unHookReceiver();
moveTaskToBack(true);
finish();
}
我需要帮助让它在 2.3 上运行
谢谢
这个异常(exception):
java.lang.SecurityException: Neither user 10156 nor current process has android.permission.MODIFY_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1322)
at android.os.Parcel.readException(Parcel.java:1276)
at com.android.internal.telephony.ITelephony$Stub$Proxy.silenceRinger(ITelephony.java:1231)
at com.y_y_full.photo_dailer.CallAnswerActivity.answerCallAidl(CallAnswerActivity.java:281)
at com.y_y_full.photo_dailer.CallAnswerActivity.answerCall(CallAnswerActivity.java:256)
at com.y_y_full.photo_dailer.CallAnswerActivity.access$3(CallAnswerActivity.java:253)
at com.y_y_full.photo_dailer.CallAnswerActivity$AnswerCallOnLongClickListener.onLongClick(CallAnswerActivity.java:181)
at android.view.View.performLongClick(View.java:2556)
at android.widget.TextView.performLongClick(TextView.java:8358)
at android.view.View$CheckForLongPress.run(View.java:9128)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
最佳答案
它在 Gingerbread 2.3.x 中不起作用的原因是 this 15031 issue , 和 15872 issue谷歌改变了电话权限的框架,这让开发人员非常恼火。虽然不能保证,但一些手机制造商保留了许可(想到的是索尼!),其他手机制造商已经从谷歌的 AOSP 中提取代码,并根据其制造过程构建自己的变体,并使用更改后的框架许可到位。
简单地说,另一种方法是让手机获得 root 权限并在电话套接字层上创建一个 MITM,并在 Android 堆栈看到事件之前进行拦截……但从表面上看,它太复杂了值得做。
现在 ICS 已经出来了,权限仍然没有改变,所以要记住这一点。同时,随着 Google 的发展,GB 源代码被遗弃,尽管在 15031 问题页面中“请修复此问题”,但几乎无能为力...
关于android - 如何拦截来电android 2.3.x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11180727/
我刚开始使用新的拦截方法,有一个基本问题,想知道如何在一个测试中链接下面的两个断言。 cy.intercept('GET', '/states').as('states'); cy.reload(tr
我有一个标签控件的自定义版本(使用用户控件构建)。在设计器中工作时,我想截取 Name 属性的设置(在属性面板中)并使用它来生成 Text 属性。也就是说,如果我在属性面板的 Name 属性中输入“l
嗨,我想通过 soapUI 解析 ssl soap 消息,而我试图通过 HttpMonitor 进行拦截它显示在异常下方 ERROR:Exception in request: javax.net.s
是否有可能从某个任意层拦截反向梯度,修改其值并继续反向传播回到网络的开始,根据您提供的修改后的梯度值更新所有先前层的反向梯度? 我知道你可以directly modify the gradients
我可以从什么 dll 中获得 Intercept 的扩展?我从 http://github.com/danielmarbach/ninject.extensions.interception 添加了
我有一个实现 onCreateOptionsMenu 方法的顶级 TabHost。我希望子 Activity (选项卡内的子 Activity )能够通过 onOptionsItemSelected
我在尝试反序列化 URL 时遇到此错误 Caused by: java.net.MalformedURLException: no protocol: www.boo.com at java.
首先,我是 Spring 的新手,这是我第一次尝试使用 Spring 编写基于 REST 的应用程序。 我计划在请求参数和响应中使用 Json。这让我想到两个问题。 有没有办法将 products="
在我基于 j_security_check 的登录表单中登录时一切正常。在这种情况下,我看到 JSESSIONID cookie 中的路径具有来自 URL 的值。但是当另一个登录页面构造动态表单(它正
我有一个我一直致力于下载文件的程序。一切正常,除非用户使用 AVG。奇怪的是,为了解决这个问题,似乎必须禁用 AVG 的“电子邮件保护”;将我的程序或 JRE 添加到异常(exception)列表不起
我正在寻找一种方法来挂接 SMSManager 或较低级别的机制,以便我可以在发送任何外发 SMS 消息之前拦截、读取和取消它们。 最佳答案 迟到总比不到好:) 我已经在这上面花了 2 天...并且不
我已成功拦截对 read() 的调用, write() , open() , unlink() , rename() , creat()但不知何故截获完全相同的语义stat()没有发生。我已经使用 L
阿里云ECS通过安全组屏蔽/拦截/阻断特定IP对云服务器的访问 所适用的场景: 通过安全组屏蔽、拦截、阻止特定IP对用户云服务器的访问,或者屏蔽IP访问服务器的特定端口。 配置的方法: 1、
我希望能够在类本身的构造函数中代理类的所有方法。 class Boy { constructor() { // proxy logic, do something before
使用 ajax 请求可以使用以下代码完成: let oldXHROpen = window.XMLHttpRequest.prototype.open; window.lastXhr = ''; wi
我想“拦截”/更改将 OData 与 Web API 一起使用时生成的 OData 查询..但我不完全确定如何“提取”生成的查询..我假设 OData 过滤器、扩展和更多一些如何生成某种表达式树或某种
当 JUnit 中的断言失败时,我想做一些“自己的事情”。我想要这个: public class MyAssert extends org.junit.Assert { // @Overrid
如何拦截 PartialFunction?例如在 Actor 中,如果我只想打印进入以下接收方法的所有内容,然后再将其传递给流程方法: class MyActor extends Actor {
我们正在使用 fluentvalidation(带有服务堆栈)来验证我们的请求 DTO。我们最近扩展了我们的框架以接受“PATCH”请求,这意味着我们现在需要仅在补丁包含要验证的字段时才应用验证。 我
我有一个作为 excel 插件运行的 WPF 应用程序,它有这样的可视化树 精益求精 元素主机 WPF 用户控件 WPF 色带条控件 现在,在 excel 中加载插件时,不会启用位于 WPF 功能区栏
我是一名优秀的程序员,十分优秀!