Приложение работает правильно
Но когда вы нажимаете кнопку «Загрузить файл» на страницах сайта, окно выбора файла не появляется
бутон загрузки - нормальный ввод. и это работает в обычном браузере
поэтому мне нужен пример кода, чтобы мое веб-представление могло получать файлы с устройства, когда участники нажимают кнопку «загрузить».
Приложение заранее получило права доступа к памяти
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
мой идентификатор веб-просмотра = webframe
lateinit var mAdView: AdView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
fab.setOnClickListener {
webframe.reload()
}
val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
)
drawer_layout.addDrawerListener(toggle)
toggle.syncState()
nav_view.setNavigationItemSelectedListener(this)
//Admob
MobileAds.initialize(this, getString(R.string.Admob_App_Id))
mAdView = findViewById(R.id.adView)
val adRequest = AdRequest.Builder().build()
mAdView.loadAd(adRequest)
//webframe
webframe.loadUrl(getString(R.string.Site_Url))
webframe.settings.javaScriptEnabled = true
webframe.settings.allowFileAccess= true
//Cach Settings
webframe.settings.setAppCacheEnabled(true)
webframe.settings.cacheMode = WebSettings.LOAD_DEFAULT
webframe.settings.setAppCachePath("/data/data/$packageName/cache")
webframe.webViewClient = callurlsin()
//Upload Mathoud
//Show Download
webframe.setDownloadListener { url, userAgent, contentDisposition, mimeType, _ ->
val request = DownloadManager.Request(Uri.parse(url))
request.setMimeType(mimeType)
request.addRequestHeader("cookie", CookieManager.getInstance().getCookie(url))
request.addRequestHeader("User-Agent", userAgent)
request.setDescription("يتم تحميل الملف...")
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType))
request.allowScanningByMediaScanner()
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalFilesDir(this@MainActivity, Environment.DIRECTORY_DOWNLOADS, ".png")
val dm = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
dm.enqueue(request)
Toast.makeText(applicationContext, "يتم تحميل الملف", Toast.LENGTH_LONG).show()
}
//Befor And After Load Page
webframe.webViewClient = object : WebViewClient(){
override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
webframe.loadUrl("file:///android_asset/404.html")
}
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
circel.visibility = View.VISIBLE
super.onPageStarted(view, url, favicon)
}
override fun onPageFinished(view: WebView?, url: String?) {
webframe.loadUrl("javascript:(function() { " +"document.getElementById('applink').style.display='none';})()")
circel.visibility = View.INVISIBLE
super.onPageFinished(view, url)
}
}
//Disable Icons Colors
nav_view.itemIconTintList = null
}//End
//back key to back
override fun onBackPressed() {
if (drawer_layout.isDrawerOpen(GravityCompat.START)) {
drawer_layout.closeDrawer(GravityCompat.START)
} else {
webframe.goBack()
}
}
//laod urls in webview
class callurlsin : WebViewClient(){
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
return false
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
when (item.itemId) {
R.id.Rating_App -> {
webframe.loadUrl("https://play.google.com/store/apps/details?id=com.aradev.net")
}
R.id.Our_Apps -> {
webframe.loadUrl("https://play.google.com/store/apps/developer?id=Mohamed+Slimane")
}
}
return true
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
// Handle navigation view item clicks here.
when (item.itemId) {
R.id.Home_Page ->{
webframe.loadUrl("https://aradev.net")
}
R.id.profile -> {
webframe.loadUrl("https://aradev.net/memberlist.php?mode=viewprofile&u=2")
}
R.id.notifications -> {
webframe.loadUrl("https://aradev.net/ucp.php?i=ucp_notifications")
}
R.id.messages -> {
webframe.loadUrl("https://aradev.net/ucp.php?i=pm&folder=inbox")
}
R.id.nav_manage -> {
webframe.loadUrl("https://aradev.net/ucp.php")
}
R.id.actevated -> {
webframe.loadUrl("https://aradev.net/search.php?search_id=active_topics")
}
R.id.nav_share -> {
val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.App_Link))
sendIntent.type = "text/plain"
startActivity(Intent.createChooser(sendIntent, "إرسال التطبيق"))
}
R.id.contact_us -> {
webframe.loadUrl("https://aradev.net/memberlist.php?mode=contactadmin")
}
}
drawer_layout.closeDrawer(GravityCompat.START)
return true
}
}