Handle PDF file upload from website with proper permission requests
This commit is contained in:
parent
8637603930
commit
00c5db0253
2 changed files with 1 additions and 24 deletions
|
|
@ -7,7 +7,6 @@ import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import android.webkit.ValueCallback
|
import android.webkit.ValueCallback
|
||||||
|
|
@ -23,7 +22,6 @@ import com.duckai.app.R
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var webView: WebView
|
private lateinit var webView: WebView
|
||||||
private lateinit var attachButton: View
|
|
||||||
private var filePathCallback: ValueCallback<Array<Uri>>? = null
|
private var filePathCallback: ValueCallback<Array<Uri>>? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -58,10 +56,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
webView = findViewById(R.id.webView)
|
webView = findViewById(R.id.webView)
|
||||||
attachButton = findViewById(R.id.attachButton)
|
|
||||||
|
|
||||||
setupWebView()
|
setupWebView()
|
||||||
setupAttachButton()
|
|
||||||
loadUrlFromIntent()
|
loadUrlFromIntent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,12 +103,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAttachButton() {
|
|
||||||
attachButton.setOnClickListener {
|
|
||||||
checkPermissionAndPickFile()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkPermissionAndPickFile() {
|
private fun checkPermissionAndPickFile() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
val permissions = arrayOf(
|
val permissions = arrayOf(
|
||||||
|
|
@ -139,7 +129,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openFilePicker() {
|
private fun openFilePicker() {
|
||||||
filePickerLauncher.launch(arrayOf("image/*", "video/*", "audio/*", "application/pdf"))
|
filePickerLauncher.launch(arrayOf("application/pdf"))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadUrlFromIntent() {
|
private fun loadUrlFromIntent() {
|
||||||
|
|
|
||||||
|
|
@ -12,17 +12,4 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
|
||||||
android:id="@+id/attachButton"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_margin="16dp"
|
|
||||||
android:layout_marginBottom="80dp"
|
|
||||||
android:contentDescription="@string/attach_file"
|
|
||||||
android:src="@drawable/ic_attach"
|
|
||||||
app:fabSize="mini"
|
|
||||||
app:tint="?attr/colorOnPrimaryContainer"
|
|
||||||
app:backgroundTint="?attr/colorPrimaryContainer" />
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue