Android 在活动中使用宽播接收器
我正在从事一个有很多活动的项目,但是当我试图在一个类中编码一个广泛的广播接收器时,广播接收器不工作,尽管我已经授予了清单文件的权限。带接收器Android 在活动中使用宽播接收器,android,Android,我正在从事一个有很多活动的项目,但是当我试图在一个类中编码一个广泛的广播接收器时,广播接收器不工作,尽管我已经授予了清单文件的权限。带接收器 <receiver android:name=".IncomingCallReciever" android:exported="true" android:enabled="true"> <intent-filter android:priority="1">actionandroid:name="android.inte
<receiver android:name=".IncomingCallReciever" android:exported="true" android:enabled="true">
<intent-filter android:priority="1">actionandroid:name="android.intent.action.NEW_OUTGOING_CALL" />
<action android:name="android.intent.action.PHONE_STATE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
actionandroid:name=“android.intent.action.NEW\u OUTGOING\u CALL”/>
我看不出您发布的XML摘录有任何错误。但是,标签android:name
中可能有错误。这应该是一个完全限定的类名(例如com.example.project.ReportReceiver
)。但是,简而言之,如果名称的第一个字符是句点(例如,.ReportReceiver
),则会将其附加到
元素中指定的包名称中。使用该快捷方式,包名应该类似于package=“com.example.project”
。在您的情况下,您应该在.incomingcallreceiver
之前检查整个包名
编辑: 检查此处是否存在问题,尤其是:
<intent-filter android:priority="1">
actionandroid:name="android.intent.action.NEW_OUTGOING_CALL" />
actionandroid:name=“android.intent.action.NEW\u OUTGOING\u CALL”/>
在android:priority=“1”之后删除
——这是一个语法问题,一旦你纠正了它,它就会工作。包名是正确的,但问题是这样的。我还有一整套其他的活动。然后,我的应用程序的一个功能就是读取接收呼叫并拒绝它(我还抛出了一些信息),但如果有任何输入呼叫发生,则不会发生任何事情。但是,当我在不同的项目中单独使用广播接收器类时,它是工作的。我只是不知道它在这个软件包中是否工作。请在此上下文中提供帮助。检查答案中的编辑。希望这有帮助。如果仍然不工作,请告诉我。
public void onReceive(Context context, Intent intent) {
mContext = context;
mIntent = intent;
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_CALL_STATE;
tm.listen(phoneStateListener, events);
}