- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在实现代码以在 android Oreo 中获取来电号码。为此,我在服务中使用广播接收器。这是我到目前为止完成的代码。
public class CallService extends Service {
private static final int ID_SERVICE = 101;
BroadcastReceiver brSms;
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
System.out.println("incomingNumber : "+incomingNumber);
Toast.makeText(context,""+incomingNumber,Toast.LENGTH_LONG).show();
}
},PhoneStateListener.LISTEN_CALL_STATE);
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.PHONE_STATE");
brSms = new MyReceiver();
registerReceiver(brSms, filter);
// Create the Foreground Service
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? createNotificationChannel(notificationManager) : "";
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
Notification notification = notificationBuilder.setOngoing(true)
.setSmallIcon(R.mipmap.ic_launcher)
.setPriority(PRIORITY_MIN)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.build();
startForeground(ID_SERVICE, notification);
}
@RequiresApi(Build.VERSION_CODES.O)
private String createNotificationChannel(NotificationManager notificationManager){
String channelId = "my_service_channelid";
String channelName = "My Foreground Service";
NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH);
channel.setImportance(NotificationManager.IMPORTANCE_NONE);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager.createNotificationChannel(channel);
return channelId;
}
@Override
public void onDestroy() {
unregisterReceiver(brSms);
}
}
代码无效。我尝试了堆栈溢出中给出的各种选项。我在 list 文件中添加了前台服务权限。如何在应用关闭或被用户杀死的情况下获取来电号码?
最佳答案
请尝试这是否适合您。
BroadcastReceiver.java
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state != null) {
if (state == TelephonyManager.EXTRA_STATE_RINGING) {
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (incomingNumber != null) {
Log.d("incomingNumber", incomingNumber);
// do what you want with the incomingNumber
}
}
}
}
}
AndroidManifest.xml
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.READ_CALL_LOG" />
</intent-filter>
</receiver>
关于android oreo 在服务中获取来电号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65460394/
以下是场景:我有一个可通过移动浏览器访问的网络应用程序。每当用户单击通过网络浏览器访问的应用程序页面中的链接时,我需要检测移动设备 IMEI 和 sim IMSI。这是为了跟踪具有相同 SIM 卡的同
场景如下:我有一个可通过移动浏览器访问的 Web 应用程序。每当用户单击可通过网络浏览器访问的我的应用程序页面中的链接时,我都需要检测移动设备的 IMEI 和 sim IMSI。这是为了跟踪具有相同
我需要在 Phonegap 为 Android 构建 HTML 移动 Web 应用程序中获取 IMEI 号码、手机号码、SIM 号码 最佳答案 你不能直接得到它们。 选项 1) 寻找一些插件,我不确定
我有一个输入框。它可能包含名称或数字。 如果输入至少有一个字母,我们将其作为名称处理,并且其长度应为 11 或更短。因此有效输入可能是 Bob、12Bob 或 Bob23。不允许有空格或其他字符,因此
我有这个要求:从客户表中 - 返回电话号码的前缀。我尝试使用字符串,将全名拆分为名字/姓氏,但它仅适用于数字。完整的nb格式为(258)1231456 最佳答案 SELECT '(258) 12314
我正在开发一个应用程序,用户必须使用手机键盘调用电话并输入验证号码。 我希望能够检测他们输入的数字是否正确。电话系统无法访问有效号码列表,但它会根据算法(如信用卡号码)验证号码。 以下是一些要求: 一
我有一张城市交通卡。我需要知道卡的援助(应用程序标识符)号码是多少。根据 EMV Book 1,我必须使用 List of AIDs 方法(第 141 页)。但是如何呢? 我还有一个 ACR122U
我想使用 javascript 分解数组中的 VIN,可能使用正则表达式,然后使用某种循环... 以下是读取 VIN 的方法: http://forum.cardekho.com/topic/600-
Here我找到了一个非常有用的答案,展示了如何使用 Whatsapp 从网站发送预填充的消息。 我们可以对 Telegram 做同样的事情吗? 最佳答案 您可以尝试使用以下方式打开 Telegram
我需要帮助完成这段代码,以便应用程序在收到推送通知时显示角标(Badge)编号,我可以收到推送通知,但应用程序上没有角标(Badge),这是代码 func application(_ applica
我正在使用 Twilio 进行入站调用,用户可以通过 Twilio-Number(从 Twilio 获得)调用应用程序并将被重定向到管理员。 现在,我们希望管理员使用相同的 Twilio 号码调用用户
C#/.NET 2.0 我需要解析一个字符串,其中包含街道名称和房屋编号的两个独立值。 in: "Streetname 1a" out: "streetname" "1a"
正如你们可能建议的那样,我正在创建一个带有语音命令的 SIRI。现在我确实想添加一个调用功能。例如我有这段代码: Intent call = new Intent(Intent.ACTION_DIAL
我想构建一个 android 应用程序,当设备第一次启动时,它会检测 IMEI 和其他设备信息,并检查是否有 SIM 卡。如果有 SIM 卡,它会发送短信包含特定号码的 IMEI 和其他设备信息。 我
我有这个对象: a = {"formData": { "total": "60.00", "tr0_RTN": "PZH", "tr0_amount": "10.00",
我正在制作一个测试工具,我有 imei 号码,但是否可以简单地或通过 NDK 更改 imei 号码。 谢谢 最佳答案 如何更改 IMEI 取决于硬件/系统,并且它是 - 至少在世界的(大部分)部分 -
我有一个表,其中有子项和父项,父项的 pid 为 0,子项的 pid 为父项的 id。我想选择父级及其子级数。 我的模型: function parent_child() {
抱歉,因为我从 android 开发跳到 IOS 开发,我想知道收到通知时是否有任何函数会触发?或者我应该如何处理通知? 这是我应用中的应用委托(delegate)。问题是每当收到消息时,如果应用程序
我正在开发应用程序,当它收到未接来电或来自手机的消息时自动发送消息。我的问题是当我从私有(private)号码收到未接来电或从私有(private)号码或服务器收到消息时(way2sms,160/2,
我想检查从联系人那里得到的电话号码是手机号码还是固定电话号码。我试过使用正则表达式,但一切都是徒劳的..任何帮助都将非常感激 最佳答案 要按手机号码和固定电话过滤联系人,您需要在数据库中有标准代码列表
我是一名优秀的程序员,十分优秀!