增加scheme文件打开
This commit is contained in:
@@ -43,6 +43,15 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
// splits {
|
||||
// abi {
|
||||
// enable true
|
||||
// reset()
|
||||
// include 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' // 指定分包的架构
|
||||
// universalApk true // 是否生成包含所有 ABI 的通用 APK
|
||||
// }
|
||||
// }
|
||||
|
||||
signingConfigs {
|
||||
own {
|
||||
storeFile file("keystore/ttstd.jks")
|
||||
@@ -73,7 +82,7 @@ android {
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
versionNameSuffix "-debug"
|
||||
versionNameSuffix "_debug"
|
||||
minifyEnabled false
|
||||
//Zipalign优化
|
||||
zipAlignEnabled true
|
||||
@@ -126,8 +135,8 @@ dependencies {
|
||||
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||
|
||||
implementation 'com.google.android.play:app-update:2.1.0'
|
||||
implementation 'com.google.android.play:app-update-ktx:2.1.0' // Kotlin扩展
|
||||
|
||||
@@ -38,6 +38,89 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".activity.xapk.XapkHandlerActivity">
|
||||
<!--from apkpure-->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:scheme="file" />
|
||||
<data android:scheme="content" />
|
||||
<data android:mimeType="*/*" />
|
||||
<data android:host="*" />
|
||||
<data android:pathPattern=".*\\.xapk" />
|
||||
<data android:pathPattern=".*\\..*\\.xapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\.xapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.xapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.xapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.xapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.xapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.xapk" />
|
||||
<data android:pathPattern=".*\\.apkm" />
|
||||
<data android:pathPattern=".*\\..*\\.apkm" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\.apkm" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.apkm" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.apkm" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.apkm" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.apkm" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.apkm" />
|
||||
<data android:pathPattern=".*\\.apks" />
|
||||
<data android:pathPattern=".*\\..*\\.apks" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\.apks" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.apks" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.apks" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.apks" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.apks" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.apks" />
|
||||
<data android:pathPattern=".*\\.sapk" />
|
||||
<data android:pathPattern=".*\\..*\\.sapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\.sapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.sapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.sapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.sapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.sapk" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.sapk" />
|
||||
<data android:pathPattern=".*\\.xapk.*" />
|
||||
<data android:pathPattern=".*\\..*\\.xapk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\.xapk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.xapk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.xapk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.xapk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.xapk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.xapk.*" />
|
||||
<data android:pathPattern=".*\\.apk" />
|
||||
<data android:pathPattern=".*\\.apk.*" />
|
||||
<data android:pathPattern=".*\\..*\\.apk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\.apk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.apk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.apk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.apk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.apk.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.apk.*" />
|
||||
<data android:pathPattern=".*\\.APK" />
|
||||
<data android:pathPattern=".*\\.APK.*" />
|
||||
<data android:pathPattern=".*\\..*\\.APK.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\.APK.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.APK.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.APK.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.APK.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.. *\\..*\\.APK.*" />
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\..*\\.APK.*" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="file" />
|
||||
<data android:scheme="content" />
|
||||
<data android:mimeType="application/xapk" />
|
||||
<data android:mimeType="application/xapk.1" />
|
||||
<data android:mimeType="application/xapk.1.1" />
|
||||
<data android:mimeType="application/xapk.1.1.1" />
|
||||
<data android:mimeType="application/xapk.1.1.1.1" />
|
||||
<data android:mimeType="application/xapk.1.1.1.1.1" />
|
||||
<data android:host="*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.update.UpdateActivity"
|
||||
android:launchMode="singleTask" />
|
||||
@@ -65,34 +148,34 @@
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
|
||||
<!-- <!– 消息接收监听器 (用户可自主扩展) –>-->
|
||||
<!-- <receiver-->
|
||||
<!-- android:name=".push.alipush.AliyunMessageReceiver"-->
|
||||
<!-- android:exported="false">-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="com.alibaba.push2.action.NOTIFICATION_OPENED" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="com.alibaba.sdk.android.push.RECEIVE" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- </receiver>-->
|
||||
<!-- <!– 消息接收监听器 (用户可自主扩展) –>-->
|
||||
<!-- <receiver-->
|
||||
<!-- android:name=".push.alipush.AliyunMessageReceiver"-->
|
||||
<!-- android:exported="false">-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="com.alibaba.push2.action.NOTIFICATION_OPENED" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- <intent-filter>-->
|
||||
<!-- <action android:name="com.alibaba.sdk.android.push.RECEIVE" />-->
|
||||
<!-- </intent-filter>-->
|
||||
<!-- </receiver>-->
|
||||
|
||||
<service
|
||||
android:name=".push.alipush.AliMessageIntentService"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_OPENED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.sdk.android.push.RECEIVE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
<service
|
||||
android:name=".push.alipush.AliMessageIntentService"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_OPENED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.push2.action.NOTIFICATION_REMOVED" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.alibaba.sdk.android.push.RECEIVE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<!-- 请填写你自己的appKey -->
|
||||
<meta-data
|
||||
@@ -104,7 +187,6 @@
|
||||
android:value="dc39560b76c54c408ece7dce2f21464f" />
|
||||
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,179 @@
|
||||
package com.example.mir4updater.activity.xapk;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.FileUtils;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.example.mir4updater.R;
|
||||
import com.example.mir4updater.activity.install.InstallActivity;
|
||||
import com.example.mir4updater.base.mvvm.BaseMvvmActivity;
|
||||
import com.example.mir4updater.databinding.ActivityXapkHandlerBinding;
|
||||
import com.hjq.permissions.OnPermissionCallback;
|
||||
import com.hjq.permissions.Permission;
|
||||
import com.hjq.permissions.XXPermissions;
|
||||
import com.hjq.toast.Toaster;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
public class XapkHandlerActivity extends BaseMvvmActivity<XapkHandlerViewModel, ActivityXapkHandlerBinding> {
|
||||
private static final String TAG = "XapkHandlerActivity";
|
||||
|
||||
private static final int REQUEST_INSTALL_CODE = 1111;
|
||||
private Uri mApkUri;
|
||||
|
||||
@Override
|
||||
public boolean setfitWindow() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_xapk_handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initDataBinding() {
|
||||
mViewModel.setCtx(this);
|
||||
mViewModel.setLifecycle(getLifecycleSubject());
|
||||
mViewModel.setVDBinding(mViewDataBinding);
|
||||
mViewDataBinding.setClick(new BtnClick());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initView() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initData() {
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && intent.getData() != null) {
|
||||
Uri uri = intent.getData();
|
||||
mApkUri = uri;
|
||||
Log.e(TAG, "initData: getScheme = " + uri.getScheme());
|
||||
Log.e(TAG, "initData: getHost = " + uri.getHost());
|
||||
Log.e(TAG, "initData: getPort = " + uri.getPort());
|
||||
Log.e(TAG, "initData: getPath = " + uri.getPath());
|
||||
Log.e(TAG, "initData: getQuery = " + uri.getQuery());
|
||||
Log.e(TAG, "initData: uri = " + uri.toString());
|
||||
mViewDataBinding.tvPath.setText(uri.toString());
|
||||
Log.e(TAG, "initData: getQueryParameter = " + uri.getQueryParameter("filepath"));
|
||||
ContentResolver resolver = getContentResolver();
|
||||
String mimeType = resolver.getType(uri); // 直接返回 MIME 类型,如 "image/jpeg"
|
||||
Log.e(TAG, "initData: mimeType = " + mimeType);
|
||||
// 从 URI 提取文件扩展名
|
||||
String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
|
||||
// 通过扩展名获取 MIME 类型
|
||||
String mimeType2 = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||
Log.e(TAG, "initData: extension = " + extension);
|
||||
Log.e(TAG, "initData: mimeType2 = " + mimeType2);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void requestPackageInstalls() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||
!getPackageManager().canRequestPackageInstalls()) {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
|
||||
.setData(Uri.parse("package:" + getPackageName()));
|
||||
startActivityForResult(intent, REQUEST_INSTALL_CODE);
|
||||
} else {
|
||||
getInstallPermission();
|
||||
}
|
||||
}
|
||||
|
||||
private void getInstallPermission() {
|
||||
XXPermissions.with(this)
|
||||
// 申请单个权限
|
||||
.permission(Permission.REQUEST_INSTALL_PACKAGES)
|
||||
// 申请多个权限
|
||||
// .permission(Permission.Group.STORAGE)
|
||||
// 设置权限请求拦截器(局部设置)
|
||||
//.interceptor(new PermissionInterceptor())
|
||||
// 设置不触发错误检测机制(局部设置)
|
||||
//.unchecked()
|
||||
.request(new OnPermissionCallback() {
|
||||
@Override
|
||||
public void onGranted(@NonNull List<String> permissions, boolean allGranted) {
|
||||
Log.e(TAG, "onGranted: permissions = " + permissions + " allGranted = " + allGranted);
|
||||
if (!allGranted) {
|
||||
// Toaster.show("获取部分权限成功,但部分权限未正常授予");
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "onGranted: 获取权限成功");
|
||||
installXapk();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {
|
||||
Log.e(TAG, "onDenied: permissions = " + permissions + " doNotAskAgain = " + doNotAskAgain);
|
||||
if (doNotAskAgain) {
|
||||
Toaster.show("被永久拒绝授权,请手动授予权限");
|
||||
// 如果是被永久拒绝就跳转到应用权限系统设置页面
|
||||
XXPermissions.startPermissionActivity(XapkHandlerActivity.this, permissions);
|
||||
} else {
|
||||
Log.e(TAG, "onGranted: 获取权限失败");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void installXapk() {
|
||||
Log.e(TAG, "installXapk: " + mApkUri.getPath());
|
||||
File file = uriToFileApiQ(mApkUri);
|
||||
if (!file.exists()) {
|
||||
Toaster.show("文件不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(XapkHandlerActivity.this, InstallActivity.class);
|
||||
intent.putExtra(InstallActivity.KEY_XAPK_PATH, file.getAbsolutePath());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
public File uriToFileApiQ(Uri uri) {
|
||||
File file = null;
|
||||
if (uri == null) return file;
|
||||
//android10以上转换
|
||||
if (uri.getScheme().equals(ContentResolver.SCHEME_FILE)) {
|
||||
file = new File(uri.getPath());
|
||||
} else if (uri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
|
||||
//把文件复制到沙盒目录
|
||||
ContentResolver contentResolver = getContentResolver();
|
||||
String displayName = System.currentTimeMillis() + Math.round((Math.random() + 1) * 1000)
|
||||
+ "." + MimeTypeMap.getSingleton().getExtensionFromMimeType(contentResolver.getType(uri));
|
||||
|
||||
try {
|
||||
InputStream is = contentResolver.openInputStream(uri);
|
||||
File cache = new File(getCacheDir().getAbsolutePath(), displayName);
|
||||
FileOutputStream fos = new FileOutputStream(cache);
|
||||
FileUtils.copy(is, fos);
|
||||
file = cache;
|
||||
fos.close();
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
public class BtnClick {
|
||||
public void installXapk(View view) {
|
||||
requestPackageInstalls();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.example.mir4updater.activity.xapk;
|
||||
|
||||
import com.example.mir4updater.base.mvvm.BaseViewModel;
|
||||
import com.example.mir4updater.databinding.ActivityXapkHandlerBinding;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
|
||||
public class XapkHandlerViewModel extends BaseViewModel<ActivityXapkHandlerBinding, ActivityEvent> {
|
||||
|
||||
@Override
|
||||
public ActivityXapkHandlerBinding getVDBinding() {
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<layout 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"
|
||||
tools:context=".activity.nstall.InstallActivity">
|
||||
tools:context=".activity.install.InstallActivity">
|
||||
|
||||
<data>
|
||||
|
||||
|
||||
45
app/src/main/res/layout/activity_xapk_handler.xml
Normal file
45
app/src/main/res/layout/activity_xapk_handler.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout 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"
|
||||
tools:context=".activity.xapk.XapkHandlerActivity">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="click"
|
||||
type="com.example.mir4updater.activity.xapk.XapkHandlerActivity.BtnClick" />
|
||||
</data>
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_path"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="file_path" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:background="@drawable/bt_upload_bg"
|
||||
android:singleLine="true"
|
||||
android:text="安装"
|
||||
android:textColor="@color/white"
|
||||
android:onClick="@{click::installXapk}"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_path" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</layout>
|
||||
@@ -24,6 +24,12 @@ buildscript {
|
||||
}
|
||||
|
||||
allprojects {
|
||||
configurations.all {
|
||||
resolutionStrategy {
|
||||
force 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
force 'androidx.annotation:annotation:1.4.0' // 强制所有依赖使用 1.4.0
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
|
||||
Reference in New Issue
Block a user