In my application i using a broadcastreceiver to receive a incoming call and shown a some details to user. It works fine, but when i opened the application and incoming call is received, it shows at top of application, not the top of incoming call screen. How to solve this issue ?
thanks in advance
Broadcast Receiver
public void onReceive(final Context context, final Intent intent) { // 1
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE); // 2
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) { // 3
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); // 4
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(context, Test1.class);
i.putExtras(intent);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(i);
}
}, 2000);
}
}
Message Showing Activity
public class Test1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.popup);
WindowManager.LayoutParams wmlp = getWindow().getAttributes();
wmlp.gravity = Gravity.BOTTOM | Gravity.LEFT;
String number = getIntent().getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
TextView tv1 = (TextView)findViewById(R.id.tv1);
tv1.setText(number);
TextView tv2 = (TextView)findViewById(R.id.tv2);
tv2.setText(MyApp.mDbh.check(number));
new Handler().postDelayed(new Runnable(){
public void run() {
finish();
}
}, 10 *1000);
}
}