how to call an activity when getting incoming call.

瘦欲@ 提交于 2019-12-03 00:47:46

Actually the full code was i posted aboove just replace the the below code

public class TestReceiver extends BroadcastReceiver{

public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(MyCallReceiver.CUSTOM_INTENT)) {
    System.out.println("GOT THE INTENT");
    context.startActivity(new Intent(context, CallActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
 }

with the below code

 public class TestReceiver extends BroadcastReceiver{

@Override
public void onReceive(final Context context, Intent intent) {
    if (intent.getAction().equals(MyCallReceiver.CUSTOM_TEST_INTENT)) {
        System.out.println("GOT THE INTENT");
        final String mobileNumber = intent.getExtras().getString("number");
        Thread thread = new Thread(){
            private int sleepTime = 400;

            @Override
            public void run() {
                super.run();
                try {
                    int wait_Time = 0;

                    while (wait_Time < sleepTime ) {
                        sleep(100);
                        wait_Time += 100;
                    }
                }catch (Exception e) {
                    Toast.makeText(context,
                            "Error Occured Because:" + e.getMessage(),
                            Toast.LENGTH_SHORT).show();
                }
                finally {

                }

                context.startActivity(new Intent(context, CallActivity.class).putExtra("number", mobileNumber)
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
            }
        };
        thread.run();
    }
}
 }

I created a thread to call my activity and in that i wrote one statement before that start activity that is sleep for 500ms . that is my solutions... if any one is not under statd then ask me i will post code here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!