小编Pav*_*zev的帖子

在 Kotlin 中创建文件夹

我是 Kotlin 的新手,读过很多教程,尝试过很多代码,但仍然不明白如何在内部存储中创建文件夹。

我需要创建一个文件夹,在其中放置 json 资源文件。

清单文件包含 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

我的代码示例是:

class MainActivity() : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val folder = File(
            Environment.getDataDirectory().toString() + separator.toString() + "MetroPol"
        )
        if (folder.exists()) {
            d("folder", "exists")
        } else {
            d("folder", "not exists")
            folder.mkdirs()
        }
    }
Run Code Online (Sandbox Code Playgroud)

我使用连接到电脑并被 Android Studio 识别的手机进行测试。当这个应用程序启动时,我进入浏览器,但没有看到任何新文件夹。

这里应该做什么?

android kotlin

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

Finding ONLY Unique Coordinates in List

I have a list of coordinates like

list_cor = 
    [[4190091.4195999987, 7410226.618699998], 
    [4190033.2124999985, 7410220.0823], 
    [4190033.2124999985, 7410220.0823], 
    [4190035.7005000003, 7410208.670500003], 
    [4190033.2124999985, 7410220.0823], 
    [4190022.768599998, 7410217.844300002]]
Run Code Online (Sandbox Code Playgroud)

I need to get only these values:

[[4190091.4195999987, 7410226.618699998], 
[4190035.7005000003, 7410208.670500003], 
[4190022.768599998, 7410217.844300002]]
Run Code Online (Sandbox Code Playgroud)

Tried numpy.unique() but it adds this item [4190033.2124999985, 7410220.0823], which I don't need.

python numpy list unique

5
推荐指数
2
解决办法
2214
查看次数

GPS 关闭时 Kotlin allCellInfo 返回 null

我在具有显示当前 CellId 功能的应用程序中遇到问题。

在各种手机上测试了这个应用程序,但其中一些手机不想显示甚至allCellInfo列表,但是,名为 Network Cell Info 的应用程序运行完美,并显示有关当前 CellId 的所有信息。

只有当我打开 GPS 时,进程才能正常工作,并且我可以看到 CID 的更新。

这是一段代码(在 SDK 29 上测试):

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@SuppressLint("MissingPermission")
fun getcids(manager: TelephonyManager): Pair<Int, String> {
    val cellInfoList = manager.allCellInfo
    if (cellInfoList != null) {
        for (networkType in cellInfoList) {
            if (networkType is CellInfoLte) {
                cid = networkType.cellIdentity.ci
                break
            }
            if (networkType is CellInfoWcdma) {
                val num = (networkType as CellInfoWcdma).cellIdentity
                cid = num.cid
                break
            }
            if (networkType is CellInfoGsm) {
                val num = (networkType as …
Run Code Online (Sandbox Code Playgroud)

android location cell kotlin

5
推荐指数
1
解决办法
789
查看次数

标签 统计

android ×2

kotlin ×2

cell ×1

list ×1

location ×1

numpy ×1

python ×1

unique ×1