Android调用程序读取RTF文件

最近由于工作原因要在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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章