我通过分享按钮将视频上传到youtube。如果我点击上传按钮,它会显示社交图标,如whatsapp,facebook,youtube。当我点击youtube时,它应该上传到youtube。
以下是我的代码:
public class MainActivity extends Activity {
private static final int SELECT_FILE1 = 1;
private static final int SELECT_FILE2 = 2;
String selectedPath1 = "NONE";
String selectedPath2 = "NONE";
TextView tv, res;
ProgressDialog progressDialog;
Button b1,b3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView)findViewById(R.id.tv);
res = (TextView)findViewById(R.id.res);
tv.setText(tv.getText() + selectedPath1);
b1 = (Button)findViewById(R.id.Button01);
b3 = (Button)findViewById(R.id.upload);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openGallery(SELECT_FILE1);
}
});
b3.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
doFileUpload();
}
});
}
public void openGallery(int req_code){
Intent intent = new Intent();
intent.setType("image/* video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select file to upload "), req_code);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK)
{
Uri selectedImageUri = data.getData();
if (requestCode == SELECT_FILE1)
{
selectedPath1 = getPath(selectedImageUri);
System.out.println("selectedPath1 : " + selectedPath1);
}
tv.setText("Selected File paths : " + selectedPath1 + "," + selectedPath2);
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
private void doFileUpload()
{
//File file1 = new File(selectedPath1);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("video/mp4");
intent.putExtra(Intent.EXTRA_STREAM, selectedPath1);
startActivity(Intent.createChooser(intent,"Upload video via:"));
}
}
选择视频后,我可以选择youtube图标。然后youtube窗口自动关闭。任何建议都非常值得赞赏。谢谢!
答案 0 :(得分:0)
试试这个:
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, "video_path");
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"share:"));
答案 1 :(得分:0)
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("video/mp4");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title_text");
intent.putExtra(Intent.EXTRA_STREAM,selectedImageUri);
startActivity(Intent.createChooser(intent,"Upload video via:"));