android点击打开文件,android:如何让我的应用程序在点击时打开特定的PDF文件

该博客展示了如何在Android应用中通过ListView点击事件打开本地SD卡上的PDF文件。当用户点击ListView中的条目时,如果文件存在,应用会尝试使用ACTION_VIEW Intent启动查看PDF的活动。如果设备上没有安装能打开PDF的应用,应用则显示一个错误提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class ghcm_Submenu1 extends Activity {

private ListView lv1;

private String lv_arr[]= {"item1", "item2"};

@Override

public void onCreate(Bundle icicle)

{

super.onCreate(icicle);

setContentView(R.layout.submenu);

lv1=(ListView)findViewById(R.id.ListView01);

// By using setAdpater method in listview we an add string array in list.

lv1.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1 , lv_arr));

lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {

public void onItemClick(AdapterView parentView, View childView, int position, long id) {

if ((position)== 0){

Intent intent = new Intent();

File file = new File("/sdcard/item1.pdf");

if (file.exists()) {

Uri path = Uri.fromFile(file);

intent.setAction(Intent.ACTION_VIEW);

intent.setDataAndType(path, "application/pdf");

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

try {

startActivity(intent);

}

catch (ActivityNotFoundException e) {

Toast.makeText(ghcm_Submenu1.this,

"No Application Available to View PDF",

Toast.LENGTH_SHORT).show();

}

}

}

else if ((position)== 1){

Intent intent = new Intent();

File file = new File("/sdcard/item2.pdf");

if (file.exists()) {

Uri path = Uri.fromFile(file);

intent.setAction(Intent.ACTION_VIEW);

intent.setDataAndType(path, "application/pdf");

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

try {

startActivity(intent);

}

catch (ActivityNotFoundException e) {

Toast.makeText(ghcm_Submenu1.this,

"No Application Available to View PDF",

Toast.LENGTH_SHORT).show();

}

}

}

}

public void onNothingSelected(AdapterView parentView) {

}

});

}

要在达梦数据库v8中创建表,您可以按照以下步骤进行操作: 1. 首先,确保您已经安装了达梦数据库v8,并按照安装文档完成了安装和配置。 2. 使用数据库管理工具或命令行连接到达梦数据库。 3. 创建一个表空间来存储您的表。您可以使用以下命令创建一个名为"TEST"的表空间: ```sql create tablespace "TEST" datafile '/home/dmdba/dmdbms/data/DMOA/TEST.DBF' size 20240 autoextend on next 1 CACHE = NORMAL; ``` 这将创建一个名为"TEST"的表空间,并指定了数据文件的路径和大小。您可以根据需要进行调整。 4. 在您选择的表空间中创建表。您可以使用常规的SQL创建表的语法来创建表,例如: ```sql create table 表名 ( 列名1 数据类型1, 列名2 数据类型2, ... ); ``` 您可以根据需要定义表的列和数据类型。 请注意,以上步骤仅涵盖了创建表的基本过程。在实际使用达梦数据库v8,您可能需要考虑其他因素,如表的约束、索引等。您可以参考达梦数据库v8的文档或使用在线文档来了解更多详细信息和操作指南。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [linux安装达梦数据库v8](https://blog.youkuaiyun.com/OceanWaves1993/article/details/129936878)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [达梦数据库v8,创建表空间、用户命令语句](https://blog.youkuaiyun.com/zhangbest2009/article/details/122146801)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值