好吧,我已經過了一段時間,我沒有得到它。多個環節中的建議都沒有解決問題。使用電子郵件意向
我已成功設置我的應用程序發送文件。目前,我正在嘗試使用我的應用程序打開這些文件。
當我點擊收到的電子郵件中的文件時,我的活動打開。
接下來我需要做的是將本地文件保存在我的應用程序使用的外部存儲文件夾中。
所以,當你點擊一個文件並且意圖過濾器打開正確的活動時,你下一步要做什麼訪問該文件?
意圖過濾器:
<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..."));
}
「我沒有代碼示例」 - 當然可以。根據你的問題,你有一個活動,你有一個''。根據你的''是什麼來做什麼的細節('ACTION_VIEW'?'ACTION_SEND'?別的?)。所以,至少給我們一些。 –
CommonsWare
夠公平的,不是那麼深,我的不好。編輯以反映我實際上做了什麼。 –
action_sendto工作得很好,我的應用程序將成功通過設備上的任何可發送應用程序發送文件。 –