【发布时间】:2015-02-15 15:48:11
【问题描述】:
我正在通过分享按钮将视频上传到 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 窗口会自动关闭。任何建议都是非常值得赞赏的。谢谢!
【问题讨论】:
标签: android android-intent video upload youtube