###前提・実現したいこと
android7 で、Webview経由のギャラリーからの写真取得をしたいと思っています。
ご教授いただけると助かります。
sdkを25に落とせば、うまく動作するのですが26にするとボタンを押した途端にアプリが落ちてしまいます。
###発生している問題・エラーメッセージ
inputボタンを押すと同時にアプリが落ちてしまいます。
01-10 22:18:31.563 27429-27429/? E/PPDaemon: Cannot open backlight 01-10 22:18:32.253 27439-27439/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.android.documentsui, PID: 27439 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.android.documentsui.model.RootInfo.equals(java.lang.Object)' on a null object reference at com.android.documentsui.BaseActivity.onRootPicked(BaseActivity.java:250) at com.android.documentsui.DocumentsActivity.onRootPicked(DocumentsActivity.java:327) at com.android.documentsui.DocumentsActivity$LoadLastUsedStackTask.finish(DocumentsActivity.java:537) at com.android.documentsui.DocumentsActivity$LoadLastUsedStackTask.finish(DocumentsActivity.java:533) at com.android.documentsui.PairedTask.onPostExecute(PairedTask.java:75) at android.os.AsyncTask.finish(AsyncTask.java:667) at android.os.AsyncTask.-wrap1(AsyncTask.java) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6173) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 01-10 22:18:36.629 27528-27528/? E/PPDaemon: Cannot open backlight 01-10 22:18:41.693 27603-27603/? E/PPDaemon: Cannot open backlight 01-10 22:18:45.756 27661-27661/? E/PPDaemon: Cannot open backlight 01-10 22:18:50.831 27733-27733/? E/PPDaemon: Cannot open backlight 01-10 22:18:55.893 27790-27790/? E/PPDaemon: Cannot open backlight 01-10 22:19:00.095 17168-17168/? E/DigitalWidget_Service: WidgetUpdateReceiver__action=android.intent.action.TIME_TICK 01-10 22:19:00.099 4092-7644/? E/ActivityManager: Sending non-protected broadcast zte.widget.action.TimeWidgetUpdate from system 17168:com.android.deskclock/1000 pkg com.android.deskclock java.lang.Throwable at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:18241) at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:18813) at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:18904) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:499) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2899) at android.os.Binder.execTransact(Binder.java:565) 01-10 22:19:00.119 17168-17168/? E/DigAppWidgetProvider: zhanghui __ updateTime:22:19 01-10 22:19:00.133 17168-17168/? E/AlarmClock: getShowHomeClock() homeTimeZone=libcore.util.ZoneInfo[id="Asia/Tokyo",mRawOffset=32400000,mEarliestRawOffset=32400000,mUseDst=false,mDstSavings=0,transitions=9] 01-10 22:19:00.955 27867-27867/? E/PPDaemon: Cannot open backlight 01-10 22:19:03.507 20078-20080/? E/QC-QMI: qmi_client [20078] d5: failed to locate client data 01-10 22:19:03.508 3087-3087/? E/QC-DS-LIB: qmuxd: RX on fd=14 returned error=0 errno[2:No such file or directory] 01-10 22:19:03.508 3087-3087/? E/QC-QMI: QMUX qmux_client_id=d5 not found in qmux client list, unable to remove 01-10 22:19:03.553 27910-27910/? E/Diag_Lib: Diag_LSM_Init: Failed to open handle to diag driver, error = 13 01-10 22:19:06.577 27955-27955/? E/PPDaemon: Cannot open backlight
###該当のソースコード
html
1<form method="post" action="text.php" enctype="multipart/form-data"> 2 3 <input type="file" name="ファイル選択"></p> 4 5 <p><input type="submit" value="送信"></p> 6 7</form>
java
1 private ValueCallback<Uri> mUploadMessage; 2 private ValueCallback<Uri[]> mFilePathCallback; 3 final private int FILECHOOSER_RESULTCODE = 1; 4 5 // ファイル選択機能を有効にし、ギャラリーから画像を所得 6 webView.setWebChromeClient(new WebChromeClient() { 7 // For Android < 3.0 8 public void openFileChooser(ValueCallback<Uri> uploadFile) { 9 openFileChooser(uploadFile, ""); 10 } 11 12 // For 3.0 <= Android < 4.1 13 public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) { 14 openFileChooser(uploadFile, acceptType, ""); 15 } 16 17 // For 4.1 <= Android < 5.0 18 public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType, String capture) { 19 if (mUploadMessage != null) { 20 mUploadMessage.onReceiveValue(null); 21 } 22 mUploadMessage = uploadFile; 23 24 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 25 intent.addCategory(Intent.CATEGORY_OPENABLE); 26 intent.setType("image/*"); 27 28 startActivityForResult(intent, FILECHOOSER_RESULTCODE); 29 } 30 31 // For Android 5.0+ 32 @Override 33 public boolean onShowFileChooser(WebView webView, 34 ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { 35 if (mFilePathCallback != null) { 36 mFilePathCallback.onReceiveValue(null); 37 } 38 mFilePathCallback = filePathCallback; 39 40 Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 41 intent.addCategory(Intent.CATEGORY_OPENABLE); 42 intent.setType("image/*"); 43 startActivityForResult(intent, FILECHOOSER_RESULTCODE); 44 45 return true; 46 } 47 }); 48 49 @Override 50 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 51 // ギャラリーから写真取得後の処理 52 if (requestCode != FILECHOOSER_RESULTCODE) { 53 super.onActivityResult(requestCode, resultCode, data); 54 return; 55 } 56 57 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 58 if (mFilePathCallback == null) { 59 super.onActivityResult(requestCode, resultCode, data); 60 return; 61 } 62 Uri[] results = null; 63 64 // Check that the response is a good one 65 if (resultCode == RESULT_OK) { 66 String dataString = data.getDataString(); 67 if (dataString != null) { 68 results = new Uri[]{Uri.parse(dataString)}; 69 } 70 } 71 72 mFilePathCallback.onReceiveValue(results); 73 mFilePathCallback = null; 74 } else { 75 if (mUploadMessage == null) { 76 super.onActivityResult(requestCode, resultCode, data); 77 return; 78 } 79 80 Uri result = null; 81 82 if (resultCode == RESULT_OK) { 83 if (data != null) { 84 result = data.getData(); 85 } 86 } 87 88 mUploadMessage.onReceiveValue(result); 89 mUploadMessage = null; 90 91 webView.clearCache(true); 92 } 93 } 94
###試したこと
sdkを25に落とせば、うまく動作するのですが26にするとボタンを押した途端にアプリが落ちてしまいます。
###補足情報(言語/FW/ツール等のバージョンなど)
androidstudio2.2/sdk26
回答1件
あなたの回答
tips
プレビュー