Android 安卓广播服务
我有一个BroadcastReceiver类(CallReceiver),它等待传入或传出呼叫。 当我的接收器接收到来电/传出呼叫时,我总是将其保存到SQLite数据库中 我有一个自动启动类它的工作很好,当我重新启动我的手机时,它总是启动我的服务 因此,当我的服务创建时,它总是创建一个新的呼叫接收器,因为我们总是等待传入/传出呼叫。 这是一项棘手的服务 当我测试我的程序时,它运行良好,但后来。。。有时有人打电话给我,那是不对的。广播接收器无法接收有效数据,或未接收到somethink 有人知道,我做错了什么? 我希望有人能帮助我。 我不知道 非常感谢 服务 公共类MyService扩展服务{Android 安卓广播服务,android,Android,我有一个BroadcastReceiver类(CallReceiver),它等待传入或传出呼叫。 当我的接收器接收到来电/传出呼叫时,我总是将其保存到SQLite数据库中 我有一个自动启动类它的工作很好,当我重新启动我的手机时,它总是启动我的服务 因此,当我的服务创建时,它总是创建一个新的呼叫接收器,因为我们总是等待传入/传出呼叫。 这是一项棘手的服务 当我测试我的程序时,它运行良好,但后来。。。有时有人打电话给我,那是不对的。广播接收器无法接收有效数据,或未接收到somethink 有人知道,
private MyReceiver rec;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.PHONE_STATE");
filter.addAction("android.intent.action.NEW_OUTGOING_CALL");
rec = new MyReceiver();
this.registerReceiver(rec, filter);
return START_STICKY;
}
}
接受者
public class MyReceiver extends BroadcastReceiver {
Bundle bundle;
String state;
String inCall, outCall;
public boolean wasRinging = false;
@Override
public void onReceive(Context context, Intent intent) {
MySingletonSQLite mySing = MySingletonSQLite.getInstance();
switch (intent.getAction())
{
case "android.intent.action.PHONE_STATE":
{
if ((bundle = intent.getExtras()) != null) {
state = bundle.getString(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
inCall = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
wasRinging = true;
// Ringing
mySing.add("incoming"+inCall);
} else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
if (wasRinging == true) {
// Live
mySing.add("already live");
}
} else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
wasRinging = false;
//Call ended
mySing.add("call ended");
}
}
break;
}
case "android.intent.action.NEW_OUTGOING_CALL":
{
if ((bundle = intent.getExtras()) != null) {
outCall = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
mySing.add("outgoing call"+outCall);
}
break;
}
}
}
}
}我们可以看一些代码吗?Stacktrace?什么不起作用?是的,我编辑了我的文章。谢谢,我们能看到一些代码吗?Stacktrace?什么不起作用?是的,我编辑了我的文章。谢谢