如何将android.net.Uri与“content://”方案转换为java.net.URI

时间:2017-04-17 14:07:10

标签: java android uri

如何将android.net.Uri与“content://”方案转换为java.net.URI =>内容://媒体/外部/视频/媒体/ 100767

我正在尝试将android.net.Uri转换为java.net.URI,如下所示:

URI javaUri = new URI(myAndroidUri.toString());

但是我收到了这个错误:

              java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://media/external/video/media/100767 (has extras) }} to activity {com.example.win.news/com.example.win.news.UploadNewsActivity}: java.lang.IllegalArgumentException: URI is not absolute: content%3A%2F%2Fmedia%2Fexternal%2Fvideo%2Fmedia%2F100767
                  at android.app.ActivityThread.deliverResults(ActivityThread.java:4067)
                  at android.app.ActivityThread.handleSendResult(ActivityThread.java:4110)
                  at android.app.ActivityThread.access$1400(ActivityThread.java:177)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:145)
                  at android.app.ActivityThread.main(ActivityThread.java:5951)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:372)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
               Caused by: java.lang.IllegalArgumentException: URI is not absolute: content%3A%2F%2Fmedia%2Fexternal%2Fvideo%2Fmedia%2F100767
                  at java.io.File.checkURI(File.java:220)
                  at java.io.File.<init>(File.java:177)
                  at com.example.win.news.UploadNewsActivity.videoToBase64(UploadNewsActivity.java:167)
                  at com.example.win.news.UploadNewsActivity.onActivityResult(UploadNewsActivity.java:129)
                  at android.app.Activity.dispatchActivityResult(Activity.java:6549)
                  at android.app.ActivityThread.deliverResults(ActivityThread.java:4063)
                  at android.app.ActivityThread.handleSendResult(ActivityThread.java:4110) 
                  at android.app.ActivityThread.access$1400(ActivityThread.java:177) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:145) 
                  at android.app.ActivityThread.main(ActivityThread.java:5951) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at java.lang.reflect.Method.invoke(Method.java:372) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

请帮助..

0 个答案:

没有答案