相关疑难解决方法(0)

Android M权限对话框未显示

我目前正在尝试将我的应用程序调整为Android M的新权限模型.

我正在收集我需要的所有权限,然后运行

Log.i("Permissions", "Requesting permissions: " + permissions);
requestPermissions(requiredPermissions.toArray(new String[requiredPermissions.size()]), requestCodeForPermissions);
Run Code Online (Sandbox Code Playgroud)

requiredPermissions拥有我需要的权限android.permission.WRITE_EXTERNAL_STORAGE.

该例程肯定是执行的,因为我在logcat中有Log行:

08-07 12:52:46.469: I/Permissions(1674): Requesting permissions: android.permission.RECEIVE_BOOT_COMPLETED; android.permission.WRITE_EXTERNAL_STORAGE
Run Code Online (Sandbox Code Playgroud)

但是权限对话框从不显示,更不用说调用onRequestPermissionsResult()了.

我究竟做错了什么?基于一些教程,我发现我没有遗漏任何东西.我只有用于测试的模拟器,没有物理设备.这是关于设置的屏幕: 图像

可能值得一提的是:如果我尝试从主屏幕打开已安装应用程序的概述,我只会得到launcher3 has exited.我不确定这可能是相关的.

有没有人知道它为什么没有显示?

permissions android android-6.0-marshmallow

68
推荐指数
6
解决办法
4万
查看次数

获取位置android Kotlin

我最近添加了获取位置功能.当我尝试显示经度和纬度时,它返回零.

这是我的LocationListener类:

inner class MylocationListener: LocationListener {
    constructor():super(){
        mylocation= Location("me")
        mylocation!!.longitude
        mylocation!!.latitude
    }

    override fun onLocationChanged(location: Location?) {
        mylocation=location
    }

    override fun onStatusChanged(p0: String?, p1: Int, p2: Bundle?) {}

    override fun onProviderEnabled(p0: String?) {}

    override fun onProviderDisabled(p0: String?) {}
}
Run Code Online (Sandbox Code Playgroud)

这是我的GetUserLocation函数:

fun GetUserLocation(){
    var mylocation= MylocationListener()
    var locationManager=getSystemService(Context.LOCATION_SERVICE) as LocationManager
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0.1f,mylocation)
}
Run Code Online (Sandbox Code Playgroud)

这是我的功能,以返回我的经度和纬度:

fun getLoction (view: View){
    prgDialog!!.show();

    GetUserLocation()

    button.setTextColor(getResources().getColor(R.color.green));
    textView.text = mylocation!!.latitude.toFloat().toString()
    Toast.makeText(this, mylocation!!.latitude.toFloat().toString(), Toast.LENGTH_LONG).show()
    Toast.makeText(this, mylocation!!.longitude.toFloat().toString(), Toast.LENGTH_LONG).show()

    prgDialog!!.hide()
} 
Run Code Online (Sandbox Code Playgroud)

android location kotlin

11
推荐指数
6
解决办法
3万
查看次数

如何获得 MANAGE_EXTERNAL_STORAGE 权限

我正在尝试在我的 Android 10 (API 29) 设备上获得MANAGE_EXTERNAL_STORAGE权限。

https://developer.android.com/training/data-storage/manage-all-files

显现:

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
Run Code Online (Sandbox Code Playgroud)

主要活动:

Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

结果是:

No Activity found to handle Intent { act=android.settings.MANAGE_APP_ALL_FILES_ACCESS_PERMISSION }
Run Code Online (Sandbox Code Playgroud)

好的,这种行为是可能的。医生说:

In some cases, a matching Activity may not exist, so ensure you safeguard against this.
Run Code Online (Sandbox Code Playgroud)

但是我怎样才能获得那个许可呢?

android android-permissions scoped-storage

9
推荐指数
1
解决办法
1万
查看次数