(内含两种方式)Android 在线查看文档world丶xls丶ppt等文件

4 篇文章 0 订阅

之前做法是偷偷下载文档调用第三方wps打开,完事后偷偷删除,说实话这样有点难受。
后来发现浏览器使用worldonline可以查看文档,放到Android自带webview上直接是一个小红叉,
点击链接直接飞到微软官网(这个方法凉凉),之前使用AgentWebview做Vue交互感觉很强大,
放到Android上在线查看文档居然可以,最后考虑使用AgentWebview加载微软在线查看工具

亲,这边建议您使用AgentWebView来加载哦!(向电商大佬看齐)

具体方法:
(普通自带webview不能使用)调用worldonline地址:   http://view.officeapps.live.com/op/view.aspx?src=
AgentWebview播放界面
public class AgentWebActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agent_web);
       //online_officelinear作为Agentwebview依附的控件
        LinearLayout online_officelinear = findViewById(R.id.online_officelinear);
        NestedScrollAgentWebView webView = new NestedScrollAgentWebView(this);
        AgentWeb.with(this)
                .setAgentWebParent(online_officelinear, new LinearLayout.LayoutParams(-1, -1))//传入AgentWeb 的父控件 ,如果父控件为 RelativeLayout , 那么第二参数需要传入 RelativeLayout.LayoutParams
                .useDefaultIndicator()
                .setWebView(webView)// 使用默认进度条
                .createAgentWeb()//
                .ready()
                .go("http://view.officeapps.live.com/op/view.aspx?src=xxxxxx.docx");//XXX替换为在线查看链接

    }
}

使用时 worldonline地址+在线文件的地址

大佬的AgentWebview地址: https://github.com/Justson/AgentWeb

AgentWebview使用:

导入依赖或者把AgentWebView作为module导入工程

使用AgentWebview需要新建一个AgentWebActivity作为打开webview的界面

AgentWebActivity的布局:
注意xxxxxxxxx,别直接复制,只需新建布局即可
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="xxxxxxxxx">
    <LinearLayout
        android:id="@+id/online_officelinear"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/colorPrimary"></LinearLayout>
</android.support.constraint.ConstraintLayout>

效果图:

客官觉得有用的点个赞

demo需要自行替换在线文档地址,使用查看doc文件链接可能需要修改后缀为大写,如出现小红叉请检查文件格式或者放到浏览器看是否能够下载

demo地址:https://github.com/sweet-guy/RecycleViewOfType

还有一种方法使用wps打开在线或者本地文件(本地必须先下载好wps)

// 专用wps工具打开word,excel,ppt
public void openFile(String path) {
//判断是否下载wps
if (!this.isAvailable(context, "cn.wps.moffice_eng")) {
    try {
        this.AlertInstallWPS(context, "market://details?id=cn.wps.moffice_eng");
    } catch (Exception var6) {
        var6.printStackTrace();
    }
  }else{
   Intent intent = new Intent();
   intent.setAction("android.intent.action.VIEW");
   intent.setClassName("cn.wps.moffice_eng", "cn.wps.moffice.documentmanager.PreStartActivity");
   Uri uri = null;
if (this.isLocal(filePath)) {
    uri = Uri.fromFile(new File(filePath));
} else {
    uri = Uri.parse(filePath);
}
   intent.setData(uri);
   startActivity(intent);
}
//判断是否本地文件
private Boolean isLocal(String filePath) {
    return filePath.startsWith("http") ? false : true;
}
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
### 回答1: 第一种方式: ```c #include <stdio.h> int main() { printf("hello world\n"); return 0; } ``` 第二种方式: ```c #include <stdio.h> void main() { puts("hello world"); } ``` 注意:第二种方式的 `puts` 函数会自动在输出字符串后换行。 ### 回答2: C语言是一种常用的编程语言,通常用来编写系统软件和应用程序。下面是两种常见的方式来编写C语言的"Hello World"程序。 方式一:使用标准库函数 ```c #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; } ``` 在这种方式,我们引入了"stdio.h"头文件,该头文件包含了输入输出操作所需的函数定义。我们通过调用`printf`函数来输出"Hello, World!"。最后,我们使用`return 0`语句来告诉操作系统程序正常结束。 方式二:不使用标准库函数 ```c #include <unistd.h> #include <sys/syscall.h> int main() { char str[] = "Hello, World!\n"; syscall(SYS_write, 1, str, sizeof(str)-1); return 0; } ``` 在这种方式,我们使用了`unistd.h`和`sys/syscall.h`头文件。我们将"Hello, World!"存储在一个字符数组,然后使用`syscall`函数调用`SYS_write`来将字符串输出到标准输出(stdout)。最后,我们同样使用`return 0`语句来结束程序。 这两种方式都可以完成"Hello, World!"的输出,选择哪种方式主要取决于实际需求和个人偏好。 ### 回答3: 在C语言,我们可以使用两种方式来编写"Hello World"程序。 第一种方式是使用标准库函数`printf()`来输出字符串"Hello World"。代码如下: ```c #include <stdio.h> int main() { printf("Hello World\n"); return 0; } ``` 在这个程序,我们首先包含了`stdio.h`头文件,这是C语言提供的标准输入输出库的头文件。然后,在`main()`函数,我们使用`printf()`函数来输出字符串"Hello World",并在末尾加上`\n`表示换行。最后,我们使用`return 0;`语句表示程序的正常结束。 第二种方式是使用无参数的`main()`函数结合`puts()`函数来输出字符串"Hello World"。代码如下: ```c #include <stdio.h> int main() { puts("Hello World"); return 0; } ``` 与前一种方式相比,这里使用了`puts()`函数来直接输出字符串,而不需要使用格式化控制符`%s`。其余部分与第一种方式相同。 总之,以上是两种常见的在C语言编写"Hello World"程序的方式。无论何种方式,这个简单的程序都是C语言学习的入门示例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值