gpt4 book ai didi

Android broadcastreceiver 似乎已停止工作

转载 作者:行者123 更新时间:2023-11-30 04:50:31 28 4
gpt4 key购买 nike

我目前正在开发一个使用 broadcastreceiver 来检查收到的短信的应用程序,但突然间它似乎停止工作了,我什至写了一个小的测试应用程序,以至少对我来说,语法上似乎是正确的,但也不起作用。

这是测试项目的代码:

list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AGApplications.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".test"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver android:name=".MsgMon">
<intent-filter>
<action android:name=
"android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

</application>

<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>

<uses-sdk android:minSdkVersion="8" />
</manifest>

广播接收器:

package com.AGApplications.test;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MsgMon extends BroadcastReceiver{

@Override
//Called when new message is received
public void onReceive(Context context, Intent intent) {
Log.d("PHONE", "Message Received");
}
}

主要 Activity :

package com.AGApplications.test;

import android.app.Activity;
import android.os.Bundle;

public class test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

据我所知我没有做错任何事,但显然我做错了!

最佳答案

所以我发现了这个问题。您不能将“PHONE”用作调试标签。不要问我为什么,因为我似乎无法弄清楚,但在使用多个不同的标签后,“PHONE”是唯一不会注册的标签。

我的 bug 似乎在别处,我又在路上了!谢谢大家的帮助!

关于Android broadcastreceiver 似乎已停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3603774/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com