在Android上使用FileProvider上传视频时出错

时间:2015-01-23 15:25:39

标签: android facebook youtube android-youtube-api android-fileprovider

我的应用在文件目录中有一个视频,我无法与其他应用共享。我正在使用FileProvider来分享Uri。但是,它似乎不适用于某些应用程序(适用于GMail和Google云端硬盘,但不适用于YouTube或Facebook)。有什么我想念的吗?

mButton.setOnClickListener( new View.OnClickListener()
        {
            @Override
            public void onClick( final View theView ) {
                File theMovie = new File( getActivity().getFilesDir() + File.separator + "Data/test.mp4" );
                Uri theMovieUri = FileProvider.getUriForFile( getActivity(), "com.test.provider_demo", theMovie );
                final Intent theShareIntent = new Intent();
                theShareIntent.setAction( Intent.ACTION_SEND );
                theShareIntent.setFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION );
                theShareIntent.putExtra( Intent.EXTRA_STREAM, theMovieUri );
                theShareIntent.setDataAndType( theMovieUri, URLConnection.guessContentTypeFromName( theMovieUri.toString() ) );

                List<ResolveInfo > theResolveInfos = getActivity().getPackageManager().queryIntentActivities( theShareIntent, PackageManager.MATCH_DEFAULT_ONLY );
                for( ResolveInfo theResolveInfo : theResolveInfos ){
                    String thePackageName = theResolveInfo.activityInfo.packageName;
                    getActivity().grantUriPermission( thePackageName, theMovieUri, Intent.FLAG_GRANT_READ_URI_PERMISSION );
                }

                getActivity().startActivity( Intent.createChooser( theShareIntent, "Share me!" ) );
            }
        } );

清单

中的FileProvider元素
   <provider
        android:authorities="com.test.provider_demo"
        android:name="android.support.v4.content.FileProvider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_provider_path" />
    </provider>

YouTube崩溃了这里的logcat

01-23 10:34:46.814  12562-13866/? E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
Process: com.google.android.youtube, PID: 12562
java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:300)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:841)
 Caused by: java.lang.NullPointerException
        at bif.a(SourceFile:504)
        at bif.a(SourceFile:85)
        at bih.doInBackground(SourceFile:274)
        at android.os.AsyncTask$2.call(AsyncTask.java:288)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841)

0 个答案:

没有答案