星期三, 11月 07, 2012

use intent to share media to YouTube or Facebook

    private void share_media(String outputFile){
        // first check if the outputFile is exists
        if (!new File(outputFile).isFile()){
            return;
        }
        ContentValues content = new ContentValues(4);
        content.put(Video.VideoColumns.TITLE, "My Test");
        content.put(Video.VideoColumns.DATE_ADDED,
        System.currentTimeMillis() / 1000);
        content.put(Video.Media.MIME_TYPE, "video/mp4");
        content.put(MediaStore.Video.Media.DATA, outputFile);
        ContentResolver resolver = getContentResolver();
        Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
     
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("video/*");
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        try {
            startActivity(Intent.createChooser(intent, "Share using"));       
        }
        catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(getApplicationContext(),"No way to share",Toast.LENGTH_LONG).show();
        }
        return;
    }

沒有留言: