android开发人员通过操作系统打开文件
嗨,有没有办法让操作系统用预定义的程序打开一个文件 我不知道它可能是什么样的文件,可能是一张照片,或者是任何东西。 我想向操作系统发出一个命令,要求它用操作系统想要的任何程序打开文件(我有文件路径)。可能是操作系统打开对话框,要求用户选择一个程序来打开文件(这对我来说没问题)android开发人员通过操作系统打开文件,android,android-intent,Android,Android Intent,嗨,有没有办法让操作系统用预定义的程序打开一个文件 我不知道它可能是什么样的文件,可能是一张照片,或者是任何东西。 我想向操作系统发出一个命令,要求它用操作系统想要的任何程序打开文件(我有文件路径)。可能是操作系统打开对话框,要求用户选择一个程序来打开文件(这对我来说没问题) 谢谢这是通过意图来完成的您需要设置操作和数据 //from inside an Activity Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.fromF
谢谢这是通过
意图来完成的
您需要设置操作和数据
//from inside an Activity
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.fromFile(theFileYouMentioned));
try{
startActivity(i);
}
catch(ActivityNotFoundException) {
//user doesn't have an app that can open this type of file
}
这是通过
Intent
完成的,您需要设置操作和数据
//from inside an Activity
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.fromFile(theFileYouMentioned));
try{
startActivity(i);
}
catch(ActivityNotFoundException) {
//user doesn't have an app that can open this type of file
}
您可以通过意图选择器执行此操作:
请参阅:您可以通过意向选择器执行此操作: 请参阅: