2016-07-09 21 views

回答

1

我曾經在Java中該代碼要求用戶選擇一個視頻,然後讓用戶選擇一個程序來打開它(轉換語法,以C#是很容易的,因爲這些API都是一樣的):

final int VIDEO_REQUEST_CODE = 5000; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_puzzle); 

    Intent intent = new Intent(Intent.ACTION_PICK, 
           MediaStore.Video.Media.EXTERNAL_CONTENT_URI); 

    startActivityForResult(intent, VIDEO_REQUEST_CODE); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if(requestCode == VIDEO_REQUEST_CODE) 
    { 
     Uri videoUri = data.getData(); 

     Intent intent = new Intent(); 
     intent.setAction(android.content.Intent.ACTION_VIEW); 

     MimeTypeMap mime = MimeTypeMap.getSingleton(); 
     ContentResolver resolver = this.getContentResolver(); 
     String type = mime.getExtensionFromMimeType(resolver.getType(videoUri)); 

     intent.setDataAndType(videoUri, type); 

     this.startActivity(intent); 
    } 
} 
+0

謝謝,那就是我一直在尋找.. 我也搜索了Java代碼..但也許我搜索了錯誤的關鍵字,因爲我什麼也沒找到 – Zananok

相關問題