Pop Up Window Over Android Native Incoming Call Screen Like True Caller Android App

How to popup window on incoming call screen like truecaller in PhoneGap Android app

I haved solve this issue using following steps

1) Add these permissions in AndroiMainFest.xml

<receiver android:name=".PhoneStateReceiver" android:enabled="true"
android:exported="true">
<intent-filter android:exported="true">
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

2) Create PhoneStateReceiver.java

public class PhoneStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
// This is where you start your service

try {
System.out.println("Receiver start");
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
Toast.makeText(context, "Incoming Call State", Toast.LENGTH_SHORT).show();
Toast.makeText(context, "Ringing State Number is -" + incomingNumber, Toast.LENGTH_SHORT).show();
}
if ((state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))) {
Toast.makeText(context, "Call Received State", Toast.LENGTH_SHORT).show();
}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
Toast.makeText(context, "Call Idle State", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}

}
}

3) Add in MainActivity.java

if (ContextCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.READ_PHONE_STATE) !=
PackageManager.PERMISSION_GRANTED) {

if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_CONTACTS)) {} else {
ActivityCompat.requestPermissions(this,
new String[] {
Manifest.permission.READ_PHONE_STATE
},
MY_PERMISSIONS_REQUEST_READ_PHONE_STATE);
}
}

4) You can on permission in setting > App > Your App > permission OR On programtically

Reference Link: http://www.theappguruz.com/blog/detecting-incoming-phone-calls-in-android

Popup over incoming-call screen

If you want to keep the Call activity still clickable, but not have any controls on your overlay, you can do this by calling

getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

In the onCreate() method of the activity that is shown over the call.

The layout parameters useable together with this are:

android:windowBackground="@android:color/transparent" 
android:windowIsTranslucent="true"
android:windowAnimationStyle="@android:style/Animation.Translucent"

StandOut window not shown during incoming call when key guard is set in Marshmallow

I have three suggestions for you to try, (not sure if they will work), but they are worth a try.

  1. try to add these flags:

    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  2. try to add a delay of let's say 2 seconds before you fire the StandOut window activity to make sure it is coming after the incoming call system screen (later, if this solves the issue, reduce the delay as much as possible).

  3. Also found this answer here, not sure if you have access to the window properties, but saw this solution:

    "We were also facing similar issue that the overlay was not displayed on a device with pin lock. The solution that worked for us is below:

    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    mParams = new LayoutParams(
    LayoutParams.MATCH_PARENT,
    LayoutParams.WRAP_CONTENT,
    LayoutParams.TYPE_SYSTEM_ERROR,
    LayoutParams.FLAG_NOT_FOCUSABLE,
    PixelFormat.TRANSLUCENT);

    It was

    LayoutParams.TYPE_SYSTEM_ERROR
    that made the difference."

    The question that is similar: Pop up window over Android native incoming call screen like true caller Android app

Hope that something here is helpful to you, please update if solved.

UPDATE: This was solved the issue: (adding this):

LayoutParams.TYPE_SYSTEM_ERROR

Just make sure to add this before the layout is inflated, otherwise it will do nothing.



Related Topics



Leave a reply



Submit