2011-01-13 7 views
1

アンドロイドアプリからプロセスを起動するにはどうすればよいですか?私は選択された曲を再生するためにデフォルトの音楽プレーヤーを起動したいです。私は自分のアプリ内から曲を再生することができますが、私はデフォルトのプレーヤーに曲を再生させたいと思います。これをどうやってやるの?アンドロイドアプリでアプリまたはファイルを起動する

ありがとうございました。これは私があなたの例を使って仕事をしたものです。

Intent intent = new Intent(android.content.Intent.ACTION_VIEW); 
      Uri data = Uri.parse("file://" + pathtofile); 
      intent.setDataAndType(data,"audio/mp3"); 
      try { 
         startActivity(intent); 
       } catch (ActivityNotFoundException e) { 
         e.printStackTrace(); 
       } 
+0

が重複する可能性(http://stackoverflow.com/questions/3114471/android-launching-music-player-using-intent) –

答えて

3

ACTION_VIEWを使用してみてください:

Uri myResourceToPlay = new Uri(...); 
Intent playIntent = new Intent(Intent.ACTION_VIEW, myResourceToPlay); 
startActivity(playIntent); 
1

私は通常、パントマイムをつかむと意図を起動するときに使用します。

try { 
     //launch intent 
     Intent i = new Intent(Intent.ACTION_VIEW); 
     Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory())); 
     String url = uri.toString(); 

     //grab mime 
     String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
       MimeTypeMap.getFileExtensionFromUrl(url)); 

     i.setDataAndType(uri, newMimeType); 
     startActivity(i); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
[Androidが意図を使用して音楽プレーヤーを起動する]の
関連する問題