我读到getAllCellInfo(所有帖子),并有像类似的情况本。下面发布的代码在 Android 6 (OnePlus One) 上运行良好,但在 Google Nexus 5x Android 8.1 API 27 上返回一个空的 Cellinfo 列表。我在清单中设置了 Permission ACCESS CORSE LOCATION 并在第一次运行应用程序时请求许可.
这是一个代码片段:
try {
TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
String networkOperator = "";
if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
networkOperator = tm.getNetworkOperator();
}
if (!TextUtils.isEmpty(networkOperator)) { //is not empty with Nexus 5x
mcc = networkOperator.substring(0, 3);
mnc = networkOperator.substring(3);
} else {
mcc = "Unbekannt";
mnc = "Unbekannt";
}
List<CellInfo> cell = tm.getAllCellInfo();
System.out.println("List: "+cell);
if (cell != null) …Run Code Online (Sandbox Code Playgroud) 我已经为电话状态更改创建了广播接收器。但广播无法正常工作。我已经尝试了几个小时并尝试了2,3个解决方案,但仍然无法正常工作。互联网上的其他人具有相同的代码,对于他们来说工作正常。我不知道我在哪里犯错。需要你的帮助!这是我的清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="veclar.map.callandsmsblocking">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".PhoneCallReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
这是我的PhoneCallReceiver类
public abstract class PhoneCallReceiver extends BroadcastReceiver {
//The receiver will be recreated whenever android feels like it. We need a static variable to remember data between instantiations
private static int lastState = …Run Code Online (Sandbox Code Playgroud) android telephony broadcastreceiver telephonymanager android-broadcastreceiver
我在情况下,我需要确定的Android来电的电话号码,但使用时 TelephonyManager.EXTRA_INCOMING_NUMBER机器人工作室警告EXTRA_INCOMING_NUMBER已被弃用。我通过电话进行筛查应该使用的developers.android.com,它显示了应用CallScreeningService API代替. 但我不知道如何使用 CallScreeningService 来获取来电号码。任何人都可以帮助我吗?
我看过类似于我的其他SO问题.但我找不到任何帮助.我已将ITelephony.java复制到com/android/internal/telephony.当我试图使用相同它说"无法解决符号ITelephony".
private ITelephony telephonyService;
Run Code Online (Sandbox Code Playgroud)
任何人都可以指出我正确的方向.任何帮助将不胜感激.
我正在尝试以编程方式从我的设备获取电话号码.我正在尝试使用以下代码:
TelephonyManager tMgr = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
mPhoneNumber = tMgr.getLine1Number();
Run Code Online (Sandbox Code Playgroud)
我在清单文件中声明了以下权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
Run Code Online (Sandbox Code Playgroud)
但是我的应用程序仍然崩溃,堆栈跟踪如下:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: toadways.ways.toad.toadways, PID: 29620
java.lang.RuntimeException: Unable to start activity ComponentInfo{toadways.ways.toad.toadways/toadways.ways.toad.toadways.RegistrationScreen}: java.lang.SecurityException: getLine1NumberForDisplay: Neither user 10240 nor current process has android.permission.READ_SMS.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.SecurityException: getLine1NumberForDisplay: Neither user 10240 nor current process has android.permission.READ_SMS.
at android.os.Parcel.readException(Parcel.java:1599) …Run Code Online (Sandbox Code Playgroud) android telephonymanager android-securityexception android-security
在android API中,根据手机连接到哪一代,提供ARFCN、UARFCN和EARFCN。它们之间有什么区别?
目前正在努力从 中读取用户短信Telephony.Sms.Inbox,获取优惠相关的短信和类别,然后以正确的方式向用户展示以使用优惠。
最近 Google 宣布他们在 Google Play 中对保护用户进行了一些更改。在博客中,他们说将来仅通过应用程序作为默认短信应用程序完全访问读取用户短信。甚至用户允许阅读短信的权限。
为了为我们的用户提供安全可靠的体验,我们进行了这些更改。
我的问题是
更新