某些手机(例如Nexus One)预先安装了Quickoffice版本,因此将文件保存到SD卡后,发送适当的Intent可能很容易。
public class OpenPdf extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) findViewById(R.id.OpenPdfButton); button.setonClickListener(new View.onClickListener() { @Override public void onClick(View v) { File file = new File("/sdcard/example.pdf"); if (file.exists()) { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); try { startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(OpenPdf.this, "No Application Available to View PDF", Toast.LENGTH_SHORT).show(); } } } }); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)