Android 如何在来电屏幕上弹出对话框活动,并从webservice检查来电者信息?
在这个项目中,我想在来电屏幕的顶部创建一个呼叫者信息Android 如何在来电屏幕上弹出对话框活动,并从webservice检查来电者信息?,android,web-services,broadcastreceiver,Android,Web Services,Broadcastreceiver,在这个项目中,我想在来电屏幕的顶部创建一个呼叫者信息对话框。为此,我尝试获取呼叫者号码,并通过此号码询问webservice用户信息。之后,我尝试在来电屏幕顶部显示一个带有联系人详细信息的对话框 但是,我的对话框活动不会显示在传入呼叫的顶部,而是在传入呼叫停止后显示。请帮忙 这是我的BroadcastReceiver课程: package homework.contactor; import android.app.AlertDialog; import android.app.Dialog;
对话框
。为此,我尝试获取呼叫者号码,并通过此号码询问webservice
用户信息。之后,我尝试在来电屏幕顶部显示一个带有联系人详细信息的对话框
但是,我的对话框活动
不会显示在传入呼叫的顶部,而是在传入呼叫停止后显示。请帮忙
这是我的BroadcastReceiver
课程:
package homework.contactor;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Handler;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class ServiceReceiver extends BroadcastReceiver {
RequestQueue queue;
private final static String NUMBERS_URL = "http://we-bright.com/numbers.php?number=";
private String customer = "Deneme";
@Override
public void onReceive(final Context context, Intent intent) {
queue = Volley.newRequestQueue(context);
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state){
case TelephonyManager.CALL_STATE_RINGING:
LoadInfo(context, incomingNumber);
Log.d("STATE", "RINGING");
break;
case TelephonyManager.CALL_STATE_IDLE:
LoadInfo(context, incomingNumber);
Log.d("STATE", "IDLE");
}
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
private void LoadInfo(final Context context, String number){
String url = NUMBERS_URL + number;
Log.d("TEL", url);
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
url,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if (response==null || response.length()==0){
return;
}
JSONArray jsonArray = null;
try {
jsonArray = response.getJSONArray("posts");
JSONObject jObject = jsonArray.getJSONObject(0);
customer = jObject.getString("name") + " " + jObject.getString("surname");
// Logging and tosting
Log.d("CUSTOMER", customer);
Toast.makeText(context, customer, Toast.LENGTH_SHORT).show();
// activity intent
openDetails(context);
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
// Add the request to the RequestQueue.
queue.add(jsonObjReq);
}
public void openDetails(final Context context){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setClassName("homework.contactor", "homework.contactor.MainActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("customer", customer);
context.startActivity(intent);
}
}, 1000);
}
}
只需将此案例添加到onCallStateChanged
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if(lastState != TelephonyManager.CALL_STATE_RINGING){
isIncoming = false;
callStartTime = new Date();
showVideoDialog(context, "outgoing Ringing: "+savedNumber);
//onOutgoingCallStarted
}
else
{
isIncoming = true;
callStartTime = new Date();
}
isIncoming = false;
callStartTime = new Date();
//
break;
只需将此案例添加到onCallStateChanged
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if(lastState != TelephonyManager.CALL_STATE_RINGING){
isIncoming = false;
callStartTime = new Date();
showVideoDialog(context, "outgoing Ringing: "+savedNumber);
//onOutgoingCallStarted
}
else
{
isIncoming = true;
callStartTime = new Date();
}
isIncoming = false;
callStartTime = new Date();
//
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//Transition of ringing->offhook are pickups of incoming calls. Nothing done on them
if(lastState != TelephonyManager.CALL_STATE_RINGING){
isIncoming = false;
callStartTime = new Date();
showVideoDialog(context, "outgoing Ringing: "+savedNumber);
//onOutgoingCallStarted
}
else
{
isIncoming = true;
callStartTime = new Date();
}
isIncoming = false;
callStartTime = new Date();
//
break;