我知道这个问题已经被问过很多次了,但我找不到合适的解决方案。但我也认为每个版本都采用了一种新方法。我目前正在尝试创建一个将记录计数器和音频文件的应用程序。此应用程序旨在成为我们审阅者的工具。我是 Android 应用程序创建领域的新手。我目前失败了,因为我想在 podcast 文件夹中添加两个或 3 个文件夹,其中保存了相应的音频文件。文件夹结构应该是:/Podcasts/风电场名称/风力涡轮机的序列号。到目前为止,我为此目的创建了以下文件:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.dirkbrekow.anzeigeundrecorder">
<uses-permission-sdk-23 android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission-sdk-23 android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission-sdk-23 android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<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/Theme.AnzeigeUndRecorder"
android:requestLegacyExternalStorage="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_marginTop="40dp">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e9e9e9"
android:hint="@string/user_hint"
android:text="@string/user_name">
</androidx.appcompat.widget.AppCompatEditText>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etWindpark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e9e9e9"
android:hint="@string/windpark_hint"
android:text="@string/windpark_name">
</androidx.appcompat.widget.AppCompatEditText>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp">
<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/etAnlage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e9e9e9"
android:hint="@string/wea_hint"
android:text="@string/wea_name">
</androidx.appcompat.widget.AppCompatEditText>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/btnStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="@string/btnStart"
android:textSize="20sp"
android:textStyle="bold"/>
</LinearLayout>
</ScrollView>
MainActivity.kt:
package de.dirkbrekow.anzeigeundrecorder
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import java.io.File
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btnStart = findViewById<Button>(R.id.btnStart)
val etName = findViewById<androidx.appcompat.widget.AppCompatEditText>(R.id.etName)
val etWindpark = findViewById<androidx.appcompat.widget.AppCompatEditText>(R.id.etWindpark)
val etAnlage = findViewById<androidx.appcompat.widget.AppCompatEditText>(R.id.etAnlage)
btnStart.setOnClickListener {
createFolder()
}
}
private fun createFolder() {
val workDirectory = File("/Podcasts/Fuchsberg/")
workDirectory.mkdirs()
}
}
提前致谢