gpt4 book ai didi

android - 如何在来电时自动启动我的 android 应用程序?

转载 作者:行者123 更新时间:2023-11-29 01:17:21 26 4
gpt4 key购买 nike

<分区>

这是我用来检测来电的代码,同时我正在烤来电号码,我想自动启动我的应用程序,所以请帮我做这件事。提前致谢。我之前也提到过这个问题的解决方案,因为发问者无法检测到来电,答案显示了如何检测来电,但我已经做到了,如上面的代码所示,现在我想要代码每当电话响起时自动启动我的应用程序,但我在那里找不到解决方案。

public class CallHelper extends Activity {

String incomingNo;

private class CallStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
// called when someone is ringing to this phone

incomingNo = incomingNumber;
Toast.makeText(ctx,
"Incoming no: "+incomingNo,
Toast.LENGTH_SHORT).show();


break;
}

}
}


public class OutgoingReceiver extends BroadcastReceiver {
public OutgoingReceiver() {
}

@Override
public void onReceive(Context context, Intent intent) {
String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(ctx,
"Outgoing: "+number,
Toast.LENGTH_LONG).show();
}

}

private Context ctx;
private TelephonyManager tm;
private CallStateListener callStateListener;

private OutgoingReceiver outgoingReceiver;

public CallHelper(Context ctx) {
this.ctx = ctx;
callStateListener = new CallStateListener();
outgoingReceiver = new OutgoingReceiver();

}
public String returnData(){
String incoming = incomingNo;
start();
callStateListener = new CallStateListener();
Log.i("check","this is return data returning :"+incoming);
return incoming;
}

public void start() {
tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);

IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
ctx.registerReceiver(outgoingReceiver, intentFilter);
}

public void stop() {
tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);
ctx.unregisterReceiver(outgoingReceiver);
}

}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com