android无法关联自定义文件类型,Android 自定义类型文件与程序关联

0x01 功能

实现在其他应用中打开某个后缀名的文件 可以直接跳转到本应用中的某个activity进行处理

0x01 实现

首先创建一个activity ,然后在manifest里对该activity项编辑,加入

这里定义的是以.file为后缀的文件,需要对自己需要的后缀名进行修改,其中pathPattern可以设置为多个,用于应对各种情况,

完善后如下

android:screenOrientation="portrait"

android:label="固件升级"

>

android:name="android.intent.action.VIEW" />

android:name="android.intent.category.DEFAULT" />

android:pathPattern="/.*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\.res" />

android:pathPattern="/.*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\..*\.res" />

android:name="android.intent.action.VIEW" />

android:name="android.intent.category.DEFAULT" />

android:pathPattern="/.*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\..*\.fw" />

android:pathPattern="/.*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\..*\.ft" />

android:pathPattern="/.*\..*\.res" />

android:pathPattern="/.*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\.res" />

android:pathPattern="/.*\..*\..*\..*\..*\..*\..*\..*\..*\..*\.res" />

android:name="android.intent.action.VIEW" />

android:name="android.intent.category.DEFAULT" />

android:mimeType="application/octet-stream" />

android:name="android.intent.action.VIEW" />

android:name="android.intent.category.DEFAULT" />

android:mimeType="application/zip" />

android:mimeType="application/x-zip-compressed" />

android:name="android.intent.action.SEND" />

android:name="android.intent.category.DEFAULT" />

可以直接从intent中拿到文件的路径

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_update_fw);

super.setTitle("res/fw 安装器");

Intent v3=this.getIntent();

String v1 = v3.getDataString();

Toast.makeText(UpdateFwActivity.this,v1,Toast.LENGTH_LONG).show();

}

0x03 效果

6ac59f0bfc339fb106c25ec82b315247.png

5aac247d084deaac52a44b6779350e16.png

参考:

https://github.com/Freeyourgadget/Gadgetbridge/blob/master/app/src/main/AndroidManifest.xml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值