Pregunta

I want to hide my application, and when users call from dialpad "1234" start my application.

I use this code but get error when call 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);
            }

        }
    }
¿Fue útil?

Solución

Try this..

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);
        }    
    }
}

And refer this for detail..

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top