Android: Presenting a notification during a call?
-
11-11-2019 - |
Pergunta
I have a broadcast receiver that listens to incoming calls. And I want to tweak the incoming call screen. Right now I can present toasts and add notifications to the notification bar (BTW the user can't pull it down because the screen is locked, before accepting the call, which kinda sucks). I tried to show an alert but it crashed - is it not allowed? Is there a way for the code in the broadcast receiver to do other things, like change the avatar of the caller or give it a name (even if it doesn't exist in the contacts). Let's just say my broadcast receiver intercepts a call - can it add the phone number and a custom avatar to the contacts, so that they will immediately be presented in the call screen?
What do you think?
Edit
I have tested vendor's code, and it worked, but it is not safe to change the UI from a background thread, so I tried to tweak his code a bit to make it thread safe but the toast doesn't appear for some reason. What do you think?
private Handler handler = new Handler();
private void showToast() {
Thread thread = new Thread(null, doBackgroundThreadProcessing, "Background");
thread.start();
}
private Runnable doBackgroundThreadProcessing = new Runnable() {
public void run() {
backgroundThreadProcessing();
}
};
private void backgroundThreadProcessing() {
handler.post(new Runnable() {
public void run() {
int count = 0;
try{
while (count < 10) {
toast.show();
Thread.sleep(1850);
count++;
}
}
catch(Exception e){
Log.e("LongToast", "", e);
}
}
});
}
Nenhuma solução correta