У меня есть следующий код, я хочу загрузить изображения на сервер в WebView в моем приложении, но не работает. Как вводить изображения из нативного приложения в WebView и загрузить на сервер.
Мой экранный снимки: [https://i.sstatic.net/65i5ctsb.pngø=/p>
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==123 && resultCode==RESULT_OK) {
// Checking whether data is null or not
if (data != null) {
// Checking for selection multiple files or single.
if (data.getClipData() != null) {
// Getting the length of data and logging up the logs using index
for (int index = 0; index < data.getClipData().getItemCount(); index++) {
// Getting the URIs of the selected files and logging them into logcat at debug level
Uri uri = data.getClipData().getItemAt(index).getUri();
Log.d("filesUri [" + uri + "] : ", String.valueOf(uri));
MainActivity.this.myWebView.loadUrl("javascript:window.INTERFACE.ximagex(document.getElementById('image').src='"+uri+"');");
}
} else {
// Getting the URI of the selected file and logging into logcat at debug level
Uri uri = data.getData();
Log.d("fileUri: ", String.valueOf(uri));
}
}
}
< /code>
} < /p>
public void timer() {
this.countDownTimer = new CountDownTimer(5000000, 5000) {
public void onTick(long millisUntilFinished) {
MainActivity.this.myWebView.loadUrl("javascript:window.INTERFACE.ximage(document.getElementById('ximage').value);");
// Intent i = new Intent(MainActivity.this, ImageActivity.class);
//startActivity(i);
if (Integer.valueOf(ximage) == 1) {
//onFinish();
Intent intent = new Intent()
.setType("image/*")
.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(Intent.createChooser(intent, "Select a file"), 123);
MainActivity.this.myWebView.loadUrl("javascript:window.INTERFACE.ximage(document.getElementById('ximage').value ='0');");
}
}
public void onFinish() {
countDownTimer.cancel();
}
}.start();
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... -to-server
Как вводить изображения из нативного приложения в WebView и загрузить на сервер ⇐ Javascript
Форум по Javascript
1752355632
Anonymous
У меня есть следующий код, я хочу загрузить изображения на сервер в WebView в моем приложении, но не работает. Как вводить изображения из нативного приложения в WebView и загрузить на сервер.
Мой экранный снимки: [https://i.sstatic.net/65i5ctsb.pngø=/p>
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==123 && resultCode==RESULT_OK) {
// Checking whether data is null or not
if (data != null) {
// Checking for selection multiple files or single.
if (data.getClipData() != null) {
// Getting the length of data and logging up the logs using index
for (int index = 0; index < data.getClipData().getItemCount(); index++) {
// Getting the URIs of the selected files and logging them into logcat at debug level
Uri uri = data.getClipData().getItemAt(index).getUri();
Log.d("filesUri [" + uri + "] : ", String.valueOf(uri));
MainActivity.this.myWebView.loadUrl("javascript:window.INTERFACE.ximagex(document.getElementById('image').src='"+uri+"');");
}
} else {
// Getting the URI of the selected file and logging into logcat at debug level
Uri uri = data.getData();
Log.d("fileUri: ", String.valueOf(uri));
}
}
}
< /code>
} < /p>
public void timer() {
this.countDownTimer = new CountDownTimer(5000000, 5000) {
public void onTick(long millisUntilFinished) {
MainActivity.this.myWebView.loadUrl("javascript:window.INTERFACE.ximage(document.getElementById('ximage').value);");
// Intent i = new Intent(MainActivity.this, ImageActivity.class);
//startActivity(i);
if (Integer.valueOf(ximage) == 1) {
//onFinish();
Intent intent = new Intent()
.setType("image/*")
.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(Intent.createChooser(intent, "Select a file"), 123);
MainActivity.this.myWebView.loadUrl("javascript:window.INTERFACE.ximage(document.getElementById('ximage').value ='0');");
}
}
public void onFinish() {
countDownTimer.cancel();
}
}.start();
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79699597/how-to-inject-images-from-native-app-to-webview-and-opload-to-server[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия