- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了一个奇怪的问题。我无法使用广播接收器接听来电。我已经双重和三次检查我的 list 文件以获得必要的权限。一切似乎都很好,但不知道为什么,接收器不工作。有人可以提出这个的原因吗?任何帮助,将不胜感激!这是我的框架代码:
主要内容:
package com.calllistener;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
public class MainActivity extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
MyPhoneStateListener phoneListener=new MyPhoneStateListener(context);
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
}
MyPhoneStateListener
类:
package com.calllistener;
import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
public class MyPhoneStateListener extends PhoneStateListener {
Context ctx;
public MyPhoneStateListener (Context ctx) {
super();
this.ctx=ctx;
}
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Log.d("DEBUG", "IDLE");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.d("DEBUG", "OFFHOOK");
break;
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(ctx, "Ringing", Toast.LENGTH_LONG).show();
Log.d("DEBUG", "RINGING");
break;
}
}
}
list :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.calllistener"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="Call listener" >
<receiver android:name="MainActivity" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
最佳答案
正如 Selvin 所说,在您的 Activity 中使用应该使用 registerReceiver(Receiver, Filter);
来初始化您的 BroadCastReceiver,仅此而已。
关于android - 来电广播接收器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26976188/
我的一位客户刚刚告诉我,在使用我为他们开发的应用程序时,他们接到来电,但 iPhone 上没有显示警报。相反,调用电话的人听到一条消息,表明用户的服务暂时不可用。 如果我们暂时搁置以下可能性:调用电话
我正在尝试在 Android 上实现 iOS callkit 行为。我收到来自 firebase 的推送通知,我想向用户显示“来电”屏幕。为此,我使用了 android.telecom 包和其他类中的
我使用 WebRTC 制作了一个简单的调用应用程序。我已建立连接,现在可以从一个浏览器调用另一个浏览器。 我仍然无法弄清楚并且在 WebRTC 标准中找不到的一件事是......我如何拒绝通话提议。
我正在使用 Twilio Java API,但我似乎无法构建将调用 Sip 分机的响应。 TwiMLResponse twiml = new TwiMLResponse(); Sip sip = ne
“如何挂断来电(当然是在 Android 中)?” 首先,我知道这个问题已经被问过和回答过好几次了,而回答总是“你不能”。但是如果我们看看市场,我们会得到一些应用程序(所有私有(private)软件,
场景如下: 显示一个 Activity (active)。如果有电话来电,Activity 应该接收到 Intent(将“来电屏幕”发送到后台/从显示屏上隐藏它),并且 Activity 本身对用户保
我用过这个方法How do I get my AVPlayer to play while app is in background?让 AVPlayer 在后台播放,以便用户可以在浏览 safari
我正在编写一个基于闹钟的应用程序,我正在寻找一种持续唤醒用户的方法。理想情况下,我希望电话能够振动、响铃和显示消息。我尝试了几种不同的选择,这是我目前拥有的: 让后台服务启动振动和播放音乐的 Acti
我的对象使用 javascript 对象原型(prototype)。 我定义了以下内容: Game = function(id, userId, tiles){ this._userId =
我正在开发 VOIP 调用应用程序。当来电显示高达 android 5.0 版时,来电显示在锁定屏幕的顶部,但从 6.0 版开始显示为通知。未出现调用屏幕。 在做了一些研发之后,在 setConten
我在 Android 上编写自己的启动器,当我使用此启动器接到 Skype 电话时,我看到来电窗口,但我无法接听电话...之后我什么也做不了,它是封锁所有。使用默认启动器和其他启动器,Skype 可以
现在怎么样了 很多问题都讨论过这个问题,但都没有提供好的解决方案。事情看起来很简单,有了 BroadcastReceiver 之后真的很容易拦截和阻止调用。出现的主要问题是默认的 Android
我正在开发一个应用程序,这个应用程序需要在某些事件发生时向用户提供明确的指示。 到目前为止我唯一能做的就是在通知区域发出通知。但是,我需要提供更明显的通知,类似于来电时电话响铃时的行为。 据我了解,a
不幸的是,Twilio 文档不够清晰,无法回答我的问题,所以我来了。 当我的应用程序在前台/后台运行时,我能够在用户调用时接收 Twilio 传入连接,并且我可以正确处理此问题(在应用程序内显示弹出窗
这可能是个愚蠢的问题,我有点菜鸟。我正在阅读这篇文章:How do I access call log for android? 在代码底部的答案中,他们有这一行: int type = Intege
我是一名优秀的程序员,十分优秀!