Android 如何在拨打电话号码时打开另一个活动;1234“;
我想隐藏我的应用程序,当用户从Android 如何在拨打电话号码时打开另一个活动;1234“;,android,broadcastreceiver,Android,Broadcastreceiver,我想隐藏我的应用程序,当用户从拨号板“1234”呼叫时,启动我的应用程序 我使用此代码,但在调用1234 public class receiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
拨号板“1234”
呼叫时,启动我的应用程序
我使用此代码,但在调用1234
public class receiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
String number = getResultData();
if (number!=null) {
if(number.equals("1234")){
Toast.makeText(context,"Gps konumunuz bekleniyor..",Toast.LENGTH_SHORT).show();
setResultData(null);
Intent newintent = new Intent(context,MainActivity.class);
newintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newintent);
}
}
}
试试这个
public class MyOutgoingCallHandler extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Extract phone number reformatted by previous receivers
String phoneNumber = getResultData();
if (phoneNumber == null) {
// No reformatted number, use the original
phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
}
if(phoneNumber.equals("1234")){ // DialedNumber checking.
// My app will bring up, so cancel the broadcast
setResultData(null);
// Start my app
Intent i=new Intent(context,MainActivity.class);
i.putExtra("extra_phone", phoneNumber);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
并参考详细信息。您可以发布您的logcat错误吗?在您的
清单中使用
。@shweta_jain如果您没有新的内容要添加,请不要编辑问题。。谢谢您的回答此代码正在运行:)。但当我输入另一个号码“5252”时,我的应用程序停止了。我怎么做?