2011-04-13 3 views
1

단순히 sdcard에 파일을 여는 프로그램을 만들려고합니다. mp3, mp4 및 apk를 열어 보았습니다. 코드가 우연히 충돌합니다.startActivity on "file : //"링크가 충돌 함

String _path = "file:///sdcard/1.apk"; 

    Uri outputFileUri = Uri.parse(_path); 
    Intent intent = new Intent(); 
    intent.setAction(Intent.ACTION_VIEW); 

시장 링크도 충돌합니다. 하지만 _path = "http://google.com"으로 설정하면 브라우저가 정상적으로 열립니다. 이 코드를 어떻게 작동시킬 수 있습니까? 다음, 당신은 (설치 후) 응용 프로그램을 실행하려는 경우

String fileName = Environment.getExternalStorageDirectory() + "/1.apk"; 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive"); 
startActivity(intent); 

: 당신은 APK를 설치하려는 경우

답변

0

, 다음 사용해야

Intent intent = new Intent(); 
intent.setClassName("com.pkg.addr", "com.pkg.addr.MainActivity"); 
startActivity(intent); 

당신은 MP3 파일 재생 플레이어를 실행하려는 경우 :

Intent intent = new Intent(android.content.Intent.ACTION_VIEW); 
Uri data = Uri.parse("file:///sdcard/1.mp3"); 
intent.setDataAndType(data,"audio/mp3"); 
startActivity(intent); 

희망하는 데 도움이됩니다.

+0

좋아요! 공장! 감사! 그래서 항상 MIME 형식을 정의해야합니까? 안드로이드는 사용자가 파일로하고 싶은 것을 선택할 수 없습니까? – POMATu

+0

안드로이드는 휴대 전화에서 처리 할 수있는 응용 프로그램 중에서 파일을 처리해야하는 응용 프로그램을 사용자가 선택할 수있게합니다. – rajath

+0

그러나 Type을 설정하지 않으면 응용 프로그램이 충돌합니다. 왜 안드로이드는 형식이 설정되어 있지 않을 때 standart openfile 대화 상자를 표시하지 않는 이유는 무엇입니까? – POMATu