###実現したいこと
onActivityResultとcreateImageFileメソッドをちゃんと使えるようにして、ファイルのアップロードをできるようにしたい。
###現状
WebViewでアプリを作っています。onShowFileChooserなど駆使して、ファイルの選択はできるようになりました。表題のメソッドを加えた状態でも、ない状態でもビルドは上手く行きます。あとは保存だけが出来ていない状況です。
下記、メソッドを加えても上手く保存出来ません。
###コード
onActivityResult
1@Override 2 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 3 if (requestCode == INPUT_FILE_REQUEST_CODE) { 4 ValueCallback mFilePathCallback = null; 5 if (mFilePathCallback == null) { 6 super.onActivityResult(requestCode, resultCode, data); 7 return; 8 } 9 Uri[] results = null; 10 11 // Check that the response is a good one 12 if (resultCode == RESULT_OK) { 13 String dataString = data.getDataString(); 14 if (dataString != null) { 15 results = new Uri[]{Uri.parse(dataString)}; 16 } 17 } 18 mFilePathCallback.onReceiveValue(results); 19 mFilePathCallback = null; 20 //return; 21 } 22 } 23//気がかりな点:The value null assigned to 'mFilePathCallback' is never used の警告
createImageFile
1private File createImageFile() throws IOException { 2 @SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 3 String imageFileName = "img_" + timeStamp + "_"; 4 File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 5 return File.createTempFile(imageFileName, ".jpg", storageDir); 6 } 7//気がかりな点:1行目のcreateImageFileにPrivate Method 'createImageFile()' is never usedの警告 8
あなたの回答
tips
プレビュー