在我的应用中,我使用以下代码创建了一个隐藏的文本文件:
logfile = new File(Environment.getExternalStorageDirectory().toString()+ "/.logfile.txt");
if(!logfile.exists()){
try {
logfile.createNewFile();
//Toast.makeText(SimpleIME.this,"File created...",Toast.LENGTH_SHORT).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(SimpleIME.this,"IOException : "+e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
这很好。它创建一个隐藏文件。然后,当我按下名为的按钮时,我想再次打开该文本文件viewlog
。
的代码viewlog
是这样的。
viewlog.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
logfile = new File(Environment.getExternalStorageDirectory().toString()+ "/.logfile.txt");
Uri uri = Uri.parse("file://" + logfile.getAbsolutePath());
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
}
});
因此,当我运行该应用程序并单击此viewlog
按钮时,它将强制关闭该应用程序。
那么如何解决这个问题呢?
原因:android.content.ActivityNotFoundException:找不到用于处理Intent的活动
logfile = new File(Environment.getExternalStorageDirectory().toString()+ "/.logfile.txt");
Uri uri = Uri.parse("file://" + logfile.getAbsolutePath());
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "text/plain");
startActivity(intent);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句