안드로이드 기본 크롬앱으로 홈페이지에 들어가서 csv 다운로드를 하면 필요한 파일이 잘 다운받아집니다.
하지만 제가만든 안드로이드 웹뷰앱을 통해 홈페이지로 들어가 csv 다운로드하기를 누르면 멀뚱멀뚱 있네요 ㅠ
파일다운로드 예제를 좀 찾아봤을때는 맨 마지막이 .jpg .mp3이런식으로 되어있으면 파일다운로드 매니저를 통해 다운받는 방식이더라고요
저같은경우 버튼을 누르면 해당 csv 파일이 만들어지고 그걸 다운받아와야하는데 좀 막막합니다. ㅠ
WebView webView;
private ValueCallback<Uri> mUploadMessage;
private ValueCallback<Uri[]> mFilePathCallback;
private String mCameraPhotoPath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
check_permission();
webView = (WebView) findViewById(R.id.main_webview);
// Enable pinch to zoom without the zoom buttons
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onCloseWindow(WebView w) {
super.onCloseWindow(w);
finish();
}
@Override
public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, Message resultMsg) {
final WebSettings settings = view.getSettings();
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
settings.setAllowFileAccess(true);
settings.setAllowContentAccess(true);
view.setWebChromeClient(this);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(view);
resultMsg.sendToTarget();
return false;
}
// For Android Version < 3.0
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
//System.out.println("WebViewActivity OS Version : " + Build.VERSION.SDK_INT + "\t openFC(VCU), n=1");
mUploadMessage = uploadMsg;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(TYPE_IMAGE);
startActivityForResult(intent, INPUT_FILE_REQUEST_CODE);
}
// For 3.0 <= Android Version < 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
//System.out.println("WebViewActivity 3<A<4.1, OS Version : " + Build.VERSION.SDK_INT + "\t openFC(VCU,aT), n=2");
openFileChooser(uploadMsg, acceptType, "");
}
// For 4.1 <= Android Version < 5.0
public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) {
Log.d(getClass().getName(), "openFileChooser : " + acceptType + "/" + capture);
mUploadMessage = uploadFile;
imageChooser();
}
// For Android Version 5.0+
// Ref: https://github.com/GoogleChrome/chromium-webview-samples/blob/master/input-file-example/app/src/main/java/inputfilesample/android/chrome/google/com/inputfilesample/MainFragment.java
public boolean onShowFileChooser(WebView webView,
ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
System.out.println("WebViewActivity A>5, OS Version : " + Build.VERSION.SDK_INT + "\t onSFC(WV,VCUB,FCP), n=3");
if (mFilePathCallback != null) {
mFilePathCallback.onReceiveValue(null);
}
mFilePathCallback = filePathCallback;
imageChooser();
return true;
}
private void imageChooser() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
} catch (IOException ex) {
// Error occurred while creating the File
Log.e(getClass().getName(), "Unable to create Image File", ex);
}
// Continue only if the File was successfully created
if (photoFile != null) {
mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
} else {
takePictureIntent = null;
}
}
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
contentSelectionIntent.setType(TYPE_IMAGE);
Intent[] intentArray;
if (takePictureIntent != null) {
intentArray = new Intent[]{takePictureIntent};
} else {
intentArray = new Intent[0];
}
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
}
});
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(URL_LOAD);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == INPUT_FILE_REQUEST_CODE && resultCode == RESULT_OK) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (mFilePathCallback == null) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
Uri[] results = new Uri[]{getResultUri(data)};
mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
} else {
if (mUploadMessage == null) {
super.onActivityResult(requestCode, resultCode, data);
return;
}
Uri result = getResultUri(data);
Log.d(getClass().getName(), "openFileChooser : " + result);
mUploadMessage.onReceiveValue(result);
mUploadMessage = null;
}
} else {
if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null);
if (mUploadMessage != null) mUploadMessage.onReceiveValue(null);
mFilePathCallback = null;
mUploadMessage = null;
super.onActivityResult(requestCode, resultCode, data);
}
}
}
혹시 몰라서 통소스 올립니다.
다운받아야하는 파일은 csv 파일 하나며 사진찍어 올리는기능과 내 문서에서 사진을 첨부하는 소스만 있는 상태입니다.
다운로드를 누르면
W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 30954
fimg library or stretchFimgApi_v5 symbol can not be loaded
해당 에러가 나옵니다.