【发布时间】:2015-01-06 16:19:35
【问题描述】:
当有人打电话给我时,我有此代码存储在数据库中,但是当有人打电话给我时,这会导致同时保存两次号码和日期,所有代码都用于我的问题电话服务..
CallBlocker = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent)
{
telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class c = null;
try {
c = Class.forName(telephonyManager.getClass().getName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Method m = null;
try {
m = c.getDeclaredMethod("getITelephony");
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
m.setAccessible(true);
try {
telephonyService = (ITelephony) m.invoke(telephonyManager);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
telephonyManager.listen(callBlockListener,PhoneStateListener.LISTEN_CALL_STATE);
}
///根据pnone状态
PhoneStateListener callBlockListener = new PhoneStateListener()
{
public void onCallStateChanged(int state,String incomingNumber)
{
if (state == TelephonyManager.CALL_STATE_RINGING)
{
if (blockAll_cb.isChecked() && sarjda)
{
Toast.makeText(getApplicationContext(), incomingNumber, Toast.LENGTH_SHORT).show();
telephonyService.endCall();
phoneNo = incomingNumber;
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String tarih = sdf.format(new Date());
gelenArama.createGelenArama(new GelenAramaItem(phoneNo, tarih));
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
triggerNotification();
}
};
timer.schedule(timerTask, 20000);
}
}
}
};
};
IntentFilter filter = new IntentFilter("android.intent.action.PHONE_STATE");
registerReceiver(CallBlocker, filter);
【问题讨论】:
-
你有什么问题?我们不是通灵者 - 仅显示您的代码和不清楚的标题不足以了解您需要什么帮助。
-
当有人打电话给我时,我在sql数据库中保存了电话号码,但是这段代码保存了两次电话。