本文介绍了如何使从我们的应用程序接听来电的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让从我给出了一些的的来电即可。总之我想打的假冒来电即可。因为我是新的,所以我不理解如何完成这个任务。
我已经创造了在那里我听电话的状态incomingCallReceiver类。
我的活动类中我打电话incomingCallReceiver类。
这是我的 IncommingCallReceiver
公共类IncommingCallReceiver扩展广播接收器
{
意图mintent;
上下文mcontext;
捆束;
公共静态字符串名称1,phoneNumber1; @覆盖
公共无效的onReceive(上下文的背景下,意图意图)
{
mintent =意图;
mcontext =背景;
捆绑= mintent.getExtras();
TelephonyManager TM =(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
INT事件= PhoneStateListener.LISTEN_CALL_STATE;
捆绑= intent.getExtras();
如果(捆绑!= NULL)
{
tm.listen(phoneStateListener,事件);
}
}私人最终PhoneStateListener phoneStateListener =新PhoneStateListener()
{ @覆盖
公共无效onCallStateChanged(INT状态,弦乐incomingNumber)
{
字符串callState =未知;
状态= bundle.getInt(TelephonyManager.EXTRA_STATE);
phoneNumber1 = bundle.getString(PHONENUMBER);
开关(州)
{ 案例TelephonyManager.CALL_STATE_IDLE:
Log.i(IncomingCallReceiver,Incomng数量:+ phoneNumber1);
Toast.makeText(mcontext,进来的电话处于闲置状态,Toast.LENGTH_LONG).show();
打破;
案例TelephonyManager.CALL_STATE_RINGING: Log.i(IncomingCallReceiver,Incomng数量:+ phoneNumber1);
Toast.makeText(mcontext,进来的电话振铃,Toast.LENGTH_LONG).show();
意图答案=新意图(Intent.ACTION_MEDIA_BUTTON);
answer.putExtra(Intent.EXTRA_KEY_EVENT,新的KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEY code_HEADSETHOOK));
mcontext.sendOrderedBroadcast(回答android.permission.CALL_PRIVILEGED);
打破;
案例TelephonyManager.CALL_STATE_OFFHOOK:
Log.i(IncomingCallReceiver,Incomng数量:+ phoneNumber1);
Toast.makeText(mcontext,进来的电话摘机,Toast.LENGTH_LONG).show();
打破;
}
Log.i(>>>广播,onCallStateChanged+ callState);
super.onCallStateChanged(州,incomingNumber);
}
};
}
解决方案
根据下面的回答了不可能的:
i am trying to make an incoming call from a number given by me. in short i want to make fake incoming call. as i am new so i am not understanding how to complete this task.i have created incomingCallReceiver class where i am listening state of phone call.
inside my activity class i am calling incomingCallReceiver class.
this is my IncommingCallReceiver
public class IncommingCallReceiver extends BroadcastReceiver
{
Intent mintent;
Context mcontext;
Bundle bundle;
public static String name1, phoneNumber1;
@Override
public void onReceive(Context context, Intent intent)
{
mintent = intent;
mcontext = context;
bundle = mintent.getExtras();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_CALL_STATE;
bundle = intent.getExtras();
if(bundle !=null)
{
tm.listen(phoneStateListener, events);
}
}
private final PhoneStateListener phoneStateListener = new PhoneStateListener()
{
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
String callState = "UNKNOWN";
state = bundle.getInt(TelephonyManager.EXTRA_STATE);
phoneNumber1 = bundle.getString("phonenumber");
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
Log.i("IncomingCallReceiver", "Incomng Number: " + phoneNumber1);
Toast.makeText(mcontext, "incomming call is idle", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.i("IncomingCallReceiver", "Incomng Number: " + phoneNumber1);
Toast.makeText(mcontext, "incomming call is ringing", Toast.LENGTH_LONG).show();
Intent answer = new Intent(Intent.ACTION_MEDIA_BUTTON);
answer.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
mcontext.sendOrderedBroadcast(answer, "android.permission.CALL_PRIVILEGED");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.i("IncomingCallReceiver", "Incomng Number: " + phoneNumber1);
Toast.makeText(mcontext, "incomming call is offhook", Toast.LENGTH_LONG).show();
break;
}
Log.i(">>>Broadcast", "onCallStateChanged " + callState);
super.onCallStateChanged(state, incomingNumber);
}
};
}
解决方案
According to the following answer its impossible:
这篇关于如何使从我们的应用程序接听来电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!