1

I try to make sample application that show contact name and number from my local contacts when incoming call, every thing work correctly but my activity dialog didn't appear till call finished or terminated. I want to show this dialog like TrueCaller Application popup when call started or find any result, My dialog started correctly when found any result but i can't show it until call finished. I cant run it on UI Thread my logic in non activity class. Any help ?

following code show how i start my activity

Intent intent = new Intent(ctx, MyDialog.class);
intent.putExtra(MyDialog.NUMBER, number);
intent.putExtra(MyDialog.CONTACT, name);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);

And i define my activity in mainfaist file

<activity
        android:name=".ui.MyDialog"
        android:excludeFromRecents="true"
        android:screenOrientation="portrait"
        android:theme="@style/dialog_activity_style"/>
Azak
  • 270
  • 1
  • 5
  • 15

2 Answers2

1

You need to cast context in your Activity.

like below code :

Intent intent = new Intent(ctx, MyDialog.class);
intent.putExtra(MyDialog.NUMBER, number);
intent.putExtra(MyDialog.CONTACT, name);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//change below line in your code
((Activity)ctx).startActivity(intent);
Chetan Joshi
  • 5,582
  • 4
  • 30
  • 43
1

You have to implement through intent service. When call is connected start service and display dialogue from service like:

AlertDialog dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();

and set permission in manifest

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Muneesh
  • 433
  • 10
  • 19