android 读取wps_Android遍历获取Office格式(Word,Excel,PPT,PDF)的文件并打开

该博客演示如何在Android应用中模仿QQ加载并查看WPS文件,包括Word、Excel、PPT等。通过ListView展示SD卡中的指定文件,点击文件列表项后调用系统应用打开。代码示例展示了文件搜索、列表加载及文件信息处理的方法。
摘要由CSDN通过智能技术生成

此案例主要是模仿QQ加载WPS(Word,Excel,PPT)本地文件可打开查看,使用ListView加载,使用线程扫描SD卡下所有目录加载指定的Word,Excel,PPT等格式的文件,ListView列表显示,点击Item则调用系统应用打开。

效果图:

代码:

public class MainActivity extends AppCompatActivity {

public ProgressDialog dialog;

private ListView mListview;

private Context context;

private List list=new ArrayList();

private String filePath = Environment.getExternalStorageDirectory().toString() + File.separator;

private static Adapter adapter;

private ACache aCache;

private String fileDate="";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mListview=(ListView) findViewById(R.id.listview);

context=this;

aCache=ACache.get(this);

onLoad();

}

public void onLoad() {

adapter=new Adapter(MainActivity.this);

String string=aCache.getAsString("file");

if(string==null)

{

showProgress();

new M

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Android应用程序中调用WPS Office手机版接口,需要使用WPS Office SDK提供的API。以下是实现此功能的基本步骤: 1. 下载WPS Office SDK并将其添加到Android项目中。 2. 在Android项目中创建一个活动,并在其中添加一个按钮或其他UI元素,以便用户可以打开WPS Office文档。 3. 实现Java代码,以调用WPS Office SDK中的API。首先,您需要创建一个WpsWrapper类,该类负责与WPS Office应用程序进行通信。然后,在该类中实现打开文档的方法。例如: ``` public class WpsWrapper { private static final String TAG = "WpsWrapper"; public static void openDocument(Context context, String filePath) { try { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setClassName("cn.wps.moffice_eng", "cn.wps.moffice.documentmanager.DocumentManager"); intent.addCategory(Intent.CATEGORY_DEFAULT); Uri uri = Uri.fromFile(new File(filePath)); intent.setDataAndType(uri, "application/msword"); context.startActivity(intent); } catch (ActivityNotFoundException e) { Log.e(TAG, "WPS Office not installed"); } } } ``` 4. 在活动中,将按钮单击事件与WpsWrapper类中的openDocument方法关联。例如: ``` public class MainActivity extends AppCompatActivity { private Button mOpenButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mOpenButton = findViewById(R.id.open_button); mOpenButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { WpsWrapper.openDocument(MainActivity.this, "/sdcard/Document.docx"); } }); } } ``` 5. 运行应用程序并单击打开按钮,WPS Office应用程序将启动并打开指定的文档。 注意:在实现此功能之前,请确保已经阅读WPS Office SDK文档,并且已经了解如何使用该SDK。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值