andywu91
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with
31 additions and
3 deletions
-
.idea/runConfigurations.xml
-
app/build.gradle
-
app/src/main/AndroidManifest.xml
-
app/src/main/java/com/wuliang/xapkinstaller/MainActivity.kt
-
lib/build.gradle
-
lib/src/main/AndroidManifest.xml
|
|
|
@ -3,7 +3,6 @@ |
|
|
|
<component name="RunConfigurationProducerService"> |
|
|
|
<option name="ignoredProducers"> |
|
|
|
<set> |
|
|
|
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" /> |
|
|
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" /> |
|
|
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" /> |
|
|
|
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" /> |
|
|
|
|
|
|
|
@ -20,7 +20,8 @@ android { |
|
|
|
} |
|
|
|
} |
|
|
|
compileOptions { |
|
|
|
sourceCompatibility = 1.8 |
|
|
|
sourceCompatibility = JavaVersion.VERSION_1_8 |
|
|
|
targetCompatibility JavaVersion.VERSION_1_8 |
|
|
|
} |
|
|
|
buildToolsVersion = '28.0.3' |
|
|
|
} |
|
|
|
|
|
|
|
@ -2,6 +2,9 @@ |
|
|
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android" |
|
|
|
package="com.wuliang.xapkinstaller"> |
|
|
|
|
|
|
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
|
|
|
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> |
|
|
|
|
|
|
|
<application |
|
|
|
android:allowBackup="true" |
|
|
|
android:icon="@mipmap/ic_launcher" |
|
|
|
|
|
|
|
@ -1,9 +1,12 @@ |
|
|
|
package com.wuliang.xapkinstaller |
|
|
|
|
|
|
|
import android.Manifest |
|
|
|
import android.content.Context |
|
|
|
import android.os.Build |
|
|
|
import android.os.Bundle |
|
|
|
import android.widget.TextView |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.core.app.ActivityCompat |
|
|
|
import com.wuliang.lib.createXapkInstaller |
|
|
|
import java.util.concurrent.ExecutorService |
|
|
|
import java.util.concurrent.Executors |
|
|
|
@ -19,6 +22,24 @@ class MainActivity : AppCompatActivity() { |
|
|
|
findViewById<TextView>(R.id.install_tv).setOnClickListener { |
|
|
|
install() |
|
|
|
} |
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 26) {//8.0 |
|
|
|
//来判断应用是否有权限安装apk |
|
|
|
val installAllowed = packageManager.canRequestPackageInstalls() |
|
|
|
//有权限 |
|
|
|
if (installAllowed) { |
|
|
|
//安装apk |
|
|
|
|
|
|
|
} else { |
|
|
|
//无权限 申请权限 |
|
|
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.REQUEST_INSTALL_PACKAGES, Manifest.permission.WRITE_EXTERNAL_STORAGE), |
|
|
|
99) |
|
|
|
} |
|
|
|
} else {//8.0以下 |
|
|
|
//安装apk |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private fun install() { |
|
|
|
|
|
|
|
@ -22,7 +22,8 @@ android { |
|
|
|
} |
|
|
|
} |
|
|
|
compileOptions { |
|
|
|
sourceCompatibility = 1.8 |
|
|
|
sourceCompatibility = JavaVersion.VERSION_1_8 |
|
|
|
targetCompatibility JavaVersion.VERSION_1_8 |
|
|
|
} |
|
|
|
buildToolsVersion = '28.0.3' |
|
|
|
|
|
|
|
|
|
|
|
@ -3,6 +3,9 @@ |
|
|
|
|
|
|
|
<application> |
|
|
|
|
|
|
|
<activity android:name=".InstallActivity" |
|
|
|
android:launchMode="singleTop"/> |
|
|
|
|
|
|
|
<provider |
|
|
|
android:name="com.wuliang.lib.UtilsFileProvider" |
|
|
|
android:authorities="${applicationId}.utilcode.provider" |
|
|
|
|