【发布时间】:2017-02-20 18:29:39
【问题描述】:
好的,我已经讨论了一段时间了,但我不明白。多个链接中的建议都没有解决问题。
我已成功设置我的应用程序以发送文件。目前,我正在尝试使用我的应用程序打开这些文件。
当我点击收到的电子邮件中的文件时,我的活动就会打开。
接下来我需要将文件保存在本地,在我的应用程序使用的外部存储文件夹中。
那么,当您单击一个文件并且意图过滤器打开正确的活动时,您接下来要做什么来访问该文件?
意图过滤器:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.gmgt" />
</intent-filter>
活动:
public class ActFileReceiver extends Activity {
private TextView label;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_receiver);
label = (TextView) findViewById(R.id.lblFileRecieverText);
}
}
用于发送文件的意图:
public void emailFile(File file) {
Uri fileURI = Uri.fromFile(file);
Intent mailIntent = new Intent(android.content.Intent.ACTION_SEND);
mailIntent.setType("messsage/vnd.com.boardmonkey.TABLETop.gamefile");
mailIntent.putExtra(Intent.EXTRA_SUBJECT, "TABLETop game file: " + file.getName());
mailIntent.putExtra(Intent.EXTRA_STREAM, fileURI);
startActivity(Intent.createChooser(mailIntent, "Send Mail With..."));
}
【问题讨论】:
-
“我没有代码示例”——当然有。根据您的问题,您有一个活动并且您有一个
<intent-filter>。做什么的细节因您的<intent-filter>的用途而异(ACTION_VIEW?ACTION_SEND?还有别的吗?)。所以,至少给我们这个。 -
还不错,没有想那么深,我的错。编辑以反映我实际拥有的东西。
-
action_sendto 工作正常,我的应用程序将通过设备上任何支持发送的应用程序成功发送文件。
标签: android android-intent android-file