最近由于工作原因要在android下读取rtf文件。在windows中可以通过word或写字板直接打开RTF文件。
在android中也有类似的软件可以打开,例如:thinkfree office
我们可以通过android调用 thinkfree office 打开rtf文件。
主要代码如下:
public class HelloActivity extends Activity implements OnClickListener {
private Button button ;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.btn);
button.setOnClickListener(this);
}
public void onClick(View v) {
String SDCardRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator;
Intent intent = getRTFFileIntent(SDCardRoot + "11.rtf");
startActivity(intent);
}
public static Intent getRTFFileIntent( String param )
{
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File(param ));
intent.setDataAndType(uri, "application/rtf");
return intent;
}
}
在三星P1010上测试结果如下:
源码下载: http://download.csdn.net/source/3462318