public class IncomingCall extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String phoneNumber;
Bundle bundle=intent.getExtras();
if(bundle!=null){
phoneNumber=bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
if(phoneNumber!=null){
DatabaseHelper databaseHelper=new DatabaseHelper();
Calendar c=Calendar.getInstance();
ContentValues contentValues=new ContentValues();
contentValues.put("incoming_number", phoneNumber);
contentValues.put("date",String.valueOf(c.get(Calendar.DATE)+"-"+c.get(Calendar.MONTH)+"-"+c.get(Calendar.YEAR)));
contentValues.put("time", String.valueOf(c.get(Calendar.HOUR_OF_DAY)+":"+c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND)));
databaseHelper.addContact(contentValues);
databaseHelper.close();
}
}
}
上面的代码在模拟器中工作正常,但在实际设备上它不再工作了。在我的应用程序中,我不想包含任何活动,那么如何解决这个问题。