我想隐藏我的应用程序,当用户从dialpad "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);
}
}
}
答案 0 :(得分:1)
试试这个..
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);
}
}
}
请参阅this了解详情..