从 Android 11 开始,面向 SDK 30+ 的应用不会向用户显示多次向应用授予后台位置权限的选项。如果最初未授予,则需要用户转到设置页面。 我们如何将用户带到正确的设置页面?
当您的应用中的某项功能在运行 Android 11 或更高版本的设备上请求后台位置时,系统对话框不包含用于启用后台位置访问的按钮。为了启用后台位置访问,用户必须在设置页面上为您的应用程序的位置权限设置始终允许选项,如有关如何请求后台位置的指南中所述。
https://developer.android.com/about/versions/11/privacy/location#change-details
授予后台位置的设置选项的用户可见标签(例如,图 3 中的始终允许)。您可以调用getBackgroundPermissionOptionLabel() 来获取此标签。此方法的返回值已本地化为用户的设备语言首选项。
https://developer.android.com/training/location/permissions#request-location-access-runtime
虽然 Android 提供了一个新的 API 来获取此设置页面标签,但没有记录的 API 可以直接调出此设置页面。您最接近的是调出特定于应用程序的设置页面,如下所述。从那里,用户必须至少执行两次点击才能深入到“权限”->“位置”以启用后台访问。这是一个繁重的过程,许多用户将无法完成。
在这个问题中已经记录了很长时间没有打开设置页面的 API,但在 Android 11 发布时更为重要,因为没有其他方式授予后台权限。
如何以编程方式打开 Android Marshmallow 上特定应用程序的权限屏幕?
它能够使用户以正确的设置页面中的第一次用户使用这样的代码问: requestPermissions(arrayOf(Manifest.permission.ACCESS_BACKGROUND_LOCATION), PERMISSION_REQUEST_BACKGROUND_LOCATION)。这只会工作一次。如果用户拒绝该权限(或什至意外回击或未授权就离开屏幕),这将永远不会再起作用,并且用户必须如上所述手动向下钻取设置。
除了指示他们在“设置”中寻找正确的页面之外,应用程序是否真的没有办法在初始拒绝后帮助用户授予后台位置权限?
我错过了什么吗?如果没有,这不是 Android 11 的主要可用性问题吗?
在第一次提示中触发正确设置页面所需的完整代码示例,但无法再次执行此操作:
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
if (checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
!= PackageManager.PERMISSION_GRANTED
) {
if (shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
val builder =
AlertDialog.Builder(this)
builder.setTitle("This app needs background location access")
builder.setMessage("Please grant location access so this app can detect beacons in the …Run Code Online (Sandbox Code Playgroud) android location android-permissions android-geofence beacon
我正在构建一个框架,我需要导入一些objective-c框架,现在我需要导入"Beaconstac.framework",但因为我们无法在swift框架项目中添加桥接头,所以我的问题是如何使用它我的项目中的框架在我试过的项目中无法直接访问
进口Beaconstac
但它给出错误"没有这样的模块"
有没有替代方法呢?
我正在尝试使用Gimbal sdk创建一个Android应用程序来检测基于Gimbal的信标,但我的应用程序无法检测到信标.但如果我尝试使用BluetoothGATT,我就能够检测到信标.以下是我的代码中侦听信标事件的部分.API密钥验证成功,但仍然无法显示邻近度.
public class MainActivity extends Activity {
private PlaceManager placeManager;
private PlaceEventListener placeEventListener;
private BeaconEventListener beaconEventListener;
private BeaconManager beaconManager;
private String TAG = "beacon";
public ArrayAdapter<String> listAdapter;
public ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
Gimbal.setApiKey(getApplication(),
"MY API KEY ");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
monitorPlace();
listenBeacon();
CommunicationManager.getInstance().startReceivingCommunications();
}
private void listenBeacon() {
BeaconEventListener beaconEventListener = getBeaconEventListener();
BeaconManager beaconManager = new BeaconManager();
beaconManager.addListener(beaconEventListener);
beaconManager.startListening();
}
private void monitorPlace() {
placeEventListener = getPlaceEventListener();
// placeManager = PlaceManager.getInstance();
// placeManager.addListener(placeEventListener);
placeManager = …Run Code Online (Sandbox Code Playgroud) 我是灯塔技术的新手,我有些疑惑.
到现在为止,我将使用Eddystone格式,因此,它们都支持Eddystone.
谢谢
我们可以让iOS设备充当iBeacon发射器,如果我们知道他们的Proximity UUID,我们可以找到附近的iBeacons.
使用Google的Proximity Beacon API,可以配置和注册真正的Beacon硬件,我们可以使用Nearby Messaging API找到它们.
但是有可能让iOS设备作为Eddystone Beacons进行广播吗?扫描Eddystone信标的应用程序需要发现它.
提前致谢.
我正在尝试将文本数据写入我的BLE设备.所以,我正在关注Android蓝牙GATT课程来完成这项任务.但我发现将文本写入特征是好的,但在尝试检索特征值时,它返回null.
MyCode:
public void writeCharacteristic(BluetoothGattCharacteristic characteristic,
String text) {
String TAGS ="MyBeacon";
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAGS, "BluetoothAdapter not initialized");
return;
} else {
Log.w(TAGS, "Writting ... ");
}
byte[] data = hexStringToByteArray(text);
Log.w(TAGS, "Writting text = " + data);
try {
characteristic.setValue(URLEncoder.encode(text, "utf-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
boolean writeValue = mBluetoothGatt.writeCharacteristic(characteristic);
Log.w(TAGS, "Writting Status = " + writeValue);
}
Run Code Online (Sandbox Code Playgroud)
//成功onCharacteristicWrite也被调用//
@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicWrite(gatt, …Run Code Online (Sandbox Code Playgroud) 当在蓝牙 LE 中发送广告数据包时,可以在 PDU 内部添加不同类型的数据。其中一些是服务数据类型,其数据类型值为: 0x16 服务数据 - 16 位 UUID 0x20 服务数据 - 32 位 UUID 0x21 服务数据 - 128 位 UUID
我见过一些使用此类数据的信标。例如,使用 0x16 后跟 0x6E2A 来发送温度。
我一直在搜索,但找不到包含所有这些服务数据的值的列表在哪里,以查看每种类型指标的代码。
我试图阻止Android信标库的调试,但它不起作用.
我在我的gradle中有这个:
compile 'org.altbeacon:android-beacon-library:2.3.3'
Run Code Online (Sandbox Code Playgroud)
我试过了:
public BeaconManager(Context ctx, org.altbeacon.beacon.BeaconManager beaconManager) {
mContext = ctx;
this.beaconManager = beaconManager;
// this is saying deprecated
this.beaconManager.setDebug(false);
// I also tried this and the same thing
org.altbeacon.beacon.logging.LogManager.setVerboseLoggingEnabled(false);
Run Code Online (Sandbox Code Playgroud)
但无论如何,我一直在获取这些日志.他们开始调试其他事情.
02-18 16:21:29.784 31809-31818/com.myapp D/ScanRecord: first manudata for manu ID
02-18 16:21:29.784 31809-31818/com.myapp D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=45:0A:1B:49:64:7F, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=[f41ef1ee-fde5-23be-5f4b-589c71babfdd], mManufacturerSpecificData={76=[2, 21, 97, 104, 113, 9, -112, 95, 68, 54, -111, -8, -26, 2, -11, 20, -55, 109, 0, 3, 17, -71, -89]}, mServiceData={}, mTxPowerLevel=-2147483648, mDeviceName=BC Beacon?], …Run Code Online (Sandbox Code Playgroud) 我一直在苦苦挣扎,我目前正在Android上使用Estimote Beacon而我正在收集他们的RSSI和TxPower以计算他们的范围.一旦我得到这些数据并且我知道它们的位置(纬度,经度,海拔高度),我需要计算我的粗略位置以用于室内位置.
提供的所有解决方案仅针对三个单点或不起作用.必须有一个现有的Java解决方案,因为它是一个常见的问题.
现在我知道之前有人问过,但在我的案例中没有任何答案真正帮助我.以下是其中一些简历:
另一个问题如果我可能会问,在我计算这个时,我应该使用什么单位来测量距离?我虽然无论使用何种距离单位都会得到相同的结果,但事实证明,如果我插入米或公里,结果会有很大变化...
最初我设置了一个BroadcastReceiver接收来自Nearby Messages API的意图.
class BeaconMessageReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Nearby.getMessagesClient(context).handleIntent(intent, object : MessageListener() {
override fun onFound(message: Message) {
val id = IBeaconId.from(message)
Timber.i("Found iBeacon=$id")
sendNotification(context, "Found iBeacon=$id")
}
override fun onLost(message: Message) {
val id = IBeaconId.from(message)
Timber.i("Lost iBeacon=$id")
sendNotification(context, "Lost iBeacon=$id")
}
})
}
private fun sendNotification(context: Context, text: String) {
Timber.d("Send notification.")
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notification = NotificationCompat.Builder(context, Notifications.CHANNEL_GENERAL)
.setContentTitle("Beacons")
.setContentText(text)
.setSmallIcon(R.drawable.ic_notification_white)
.build() …Run Code Online (Sandbox Code Playgroud) android android-intentservice android-ble beacon google-nearby