对于ICS,JB(4.1,4.2,4.3),startActivityForResult返回null

时间:2015-03-21 14:55:01

标签: android android-webview

这是WebView-Android中文件上传的一段代码。 这为ICS和JB返回null。选择文件活动崩溃后,文件选择器将打开。可能是什么问题呢? 什么应该是KK的代码? (摘自GitHub(@GauntFace)。

@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
Uri[] results = null;

// Check that the response is a good one
if (resultCode == Activity.RESULT_OK) {
    if (intent == null) {
        // If there is not data, then we may have taken a photo
        if (mCameraPhotoPath == null) {
            results = new Uri[] {
                Uri.parse(mCameraPhotoPath)
            };
        }
    } else {
        String dataString = intent.getDataString();
        if (dataString != null) {
            results = new Uri[] {
                Uri.parse(dataString)
            };
        }
    }
}

mFilePathCallback.onReceiveValue(results);
mFilePathCallback = null;
}

以下是openFileChooser的代码:

webView.setWebChromeClient(new WebChromeClient() {
    // For Android 3.0+, ICS 4.0
    public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.setType("*/*");
        Upload.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), Upload.FILECHOOSER_RESULTCODE);
    }

    // For Android 4.1+
    public void openFileChooser(ValueCallback < Uri > uploadMsg, String acceptType, String capture) {
        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.setType("*/*");
        Upload.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), Upload.FILECHOOSER_RESULTCODE);
    }

    // For Android 4.1+ (different params)
    public void openFileChooser(ValueCallback < Uri > uploadMsg) {
        mUploadMessage = uploadMsg;
        Intent i = new Intent(Intent.ACTION_GET_CONTENT);
        i.setType("*/*");
        Upload.this.startActivityForResult(Intent.createChooser(i, "File Chooser"), Upload.FILECHOOSER_RESULTCODE);
    }
}
}

logcat的:

java.lang.RuntimeException: Failure delivering result ResultInfo {
        who = null, request = 1, result = -1, data = Intent {
                dat = content: //com.estrongs.files/storage/sdcard/0/abc.pdf }} to activity {com.example.xyz.Upload}: java.lang.NullPointerException
                    at android.app.ActivityThread.deliverResults(ActivityThread.java: 3367)
                at android.app.ActivityThread.handleSendResult(ActivityThread.java: 3410)
                at android.app.ActivityThread.access$1100(ActivityThread.java: 141)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1304)
                at android.os.Handler.dispatchMessage(Handler.java: 99)
                at android.os.Looper.loop(Looper.java: 137)
                at android.app.ActivityThread.main(ActivityThread.java: 5103)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java: 525)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 737)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 553)
                at dalvik.system.NativeStart.main(Native Method)
                Caused by: java.lang.NullPointerException
                at com.example.xyz.Upload.onActivityResult(Upload.java: 84)
                at android.app.Activity.dispatchActivityResult(Activity.java: 5322)
                at android.app.ActivityThread.deliverResults(ActivityThread.java: 3363)
                at android.app.ActivityThread.handleSendResult(ActivityThread.java: 3410)
                at android.app.ActivityThread.access$1100(ActivityThread.java: 141)
                at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1304)
                at android.os.Handler.dispatchMessage(Handler.java: 99)
                at android.os.Looper.loop(Looper.java: 137)  
                at android.app.ActivityThread.main(ActivityThread.java: 5103)  
                at java.lang.reflect.Method.invokeNative(Native Method)         
                at java.lang.reflect.Method.invoke(Method.java: 525)           
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 737)          
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 553)        
                at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案