在我的应用程序中,我将数据保存到Excel文件中,并为用户提供:
所有东西都可以在我的设备上正常工作,但问题是:
CODE
/**
* Opening saved file.
*
* @param file
* - File to be opened
*/
private void openSavedFile(File file) {
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
this.startActivity(intent);
}
/**
* Open a file browser and shows the folder which contains the file passed
* as a parameter.
*
* @param file
* - File to be shown in file browser
*/
public void openFolder(File file) {
if (file.exists()) {
file = file.getParentFile();
Uri selectedUri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(selectedUri, "resource/folder");
startActivity(intent);
}
}
/**
* Sends a file by email in attachment
*
* @param file
* - file to be sent
*/
private void sendReportByMail(File file) {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
// setting the type
emailIntent.setData(Uri.parse("mailto:"));
// the attaching the file
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
// the mail subject
emailIntent.putExtra(Intent.EXTRA_SUBJECT, createEmailSubject());
// starting email intent with chooser
startActivity(Intent.createChooser(emailIntent, this.getResources()
.getString(R.string.report_email_chooser)));
}
答案 0 :(得分:3)
检查你触发的隐含意图,任何活动都是他们处理那个火灾意图
PackageManager packageManager = getActivity().getPackageManager();
if (intent.resolveActivity(packageManager) != null) {
//Gotactivity to handle intent
startActivity(intent);
} else {
Log.d(TAG, "No Intent available to handle action");
}