我正在创建一个名为ROME的应用程序,关于罗马市。我有一个名为eten的活动,意思是食物,我希望活动在打开时打开一个名为etenlijst.pdf的pdf文件。
我得到了以下代码:
public class Eten extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_eten);
// Show the Up button in the action bar.
// getActionBar().setDisplayHomeAsUpEnabled(true);
/**** This looks like a good place for it *****/
Button OpenPDF = (Button) findViewById(R.id.OpenPdfButton);
OpenPDF.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
File pdfFile = new File("/ROME/Etenlijst.pdf");
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(Eten.this, "Installeer een geschikte applicatie om PDF's mee te openen", Toast.LENGTH_LONG).show();
}
}
}
});
}
}
但每当我在我的应用程序中进行此活动或单击按钮时,它将无法打开文件或提供吐司? 你现在为什么?
提前致谢, 井