├── .github └── workflows │ └── android.yml ├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── main │ ├── AndroidManifest.xml │ ├── ic_launcher-playstore.png │ ├── java │ │ └── com │ │ │ └── twiceyuan │ │ │ └── wxapk │ │ │ ├── AppFileProvider.kt │ │ │ ├── FileBrowserActivity.kt │ │ │ ├── InstallerActivity.kt │ │ │ ├── MainActivity.kt │ │ │ ├── PermissionHandlerActivity.kt │ │ │ ├── ShadowActivity.kt │ │ │ └── ToastExt.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ └── ic_launcher_foreground.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── ic_launcher_background.xml │ │ ├── keys.xml │ │ ├── strings.xml │ │ └── styles.xml │ │ └── xml │ │ └── file_paths.xml │ └── test │ └── java │ └── com │ └── twiceyuan │ └── wxapk │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Build & Publish Release APK 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | Gradle: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: checkout code 13 | uses: actions/checkout@v2 14 | 15 | - name: setup jdk 16 | uses: actions/setup-java@v3 17 | with: 18 | distribution: 'temurin' 19 | java-version: '17' 20 | 21 | - name: Decrypt the keystore 22 | run: | 23 | echo "${{ secrets.RELEASE_KEYSTORE }}" > release.keystore.asc 24 | gpg -d --passphrase "${{ secrets.RELEASE_KEYSTORE_PASSPHRASE }}" --batch release.keystore.asc > app/release.keystore 25 | 26 | - name: Make Gradle executable 27 | run: chmod +x ./gradlew 28 | 29 | - name: Build Release APK 30 | run: | 31 | export TWICEYUAN_KEYSTORE="release.keystore" 32 | export TWICEYUAN_KEYSTORE_PASSWD="${{ secrets.KEYSTORE_PASSWORD }}" 33 | export TWICEYUAN_KEY_PASSWD="${{ secrets.KEY_PASSWORD }}" 34 | export TWICEYUAN_KEY_ALIAS="${{ secrets.KEY_ALIAS }}" 35 | 36 | ./gradlew assembleRelease 37 | 38 | - name: Create Draft Release 39 | id: create_release 40 | uses: actions/create-release@v1 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | with: 44 | tag_name: ${{ github.ref }} 45 | release_name: Release ${{ github.ref }} 46 | draft: true 47 | prerelease: false 48 | 49 | - name: Upload assets 50 | uses: csexton/release-asset-action@v2 51 | with: 52 | release-url: ${{ steps.create_release.outputs.upload_url }} 53 | github-token: ${{ secrets.GITHUB_TOKEN }} 54 | pattern: "app/build/outputs/apk/release/*-release.apk" 55 | 56 | - name: Publish release 57 | uses: eregon/publish-release@v1 58 | env: 59 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 60 | with: 61 | release_id: ${{ steps.create_release.outputs.id }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | app/release 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 twiceYuan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WXAPK 2 | 3 | ![logo](app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png) 4 | 5 | 在微信中直接安装接收到的 APK 文件 6 | 7 | ## 原理 8 | 9 | 微信为了提高恶意软件传播的成本,简单粗暴的在微信中传播的 APK 文件名后缀改为 .apk.1。 10 | 本 App 通过定义 apk.1 的 Intent Filter 来识别这种文件类型,分发给系统的应用安装器进行正常安装。 11 | 12 | > [!CAUTION] 13 | > 请自行确认收到的 APK 文件是可信任的,谨慎安装来源不明的 APK 文件 14 | 15 | ## 下载 16 | 17 | 18 | 下载应用,请到 Google Play 19 | 20 | 21 | 或 22 | 23 | [Releases](https://github.com/twiceyuan/WXAPK/releases) 24 | 25 | ## License 26 | 27 | MIT 28 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | compileSdk = 34 6 | 7 | buildFeatures { 8 | viewBinding = true 9 | } 10 | 11 | defaultConfig { 12 | applicationId "com.twiceyuan.wxapk" 13 | minSdk = 21 14 | targetSdk = 34 15 | namespace = "com.twiceyuan.wxapk" 16 | versionCode getAppVersionCode() 17 | versionName getLastTagName() 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | } 20 | 21 | signingConfigs { 22 | release { 23 | if (System.getenv("CI") != null) { 24 | storeFile file(System.env.TWICEYUAN_KEYSTORE) 25 | storePassword System.env.TWICEYUAN_KEYSTORE_PASSWD 26 | keyAlias System.env.TWICEYUAN_KEY_ALIAS 27 | keyPassword System.env.TWICEYUAN_KEY_PASSWD 28 | } else { 29 | String keystore = System.env.WXAPK_KEYSTORE 30 | storeFile file(keystore == null ? "/dev/null" : keystore) 31 | storePassword System.env.WXAPK_KEYSTORE_PASSWD 32 | keyAlias System.env.WXAPK_KEY_ALIAS 33 | keyPassword System.env.WXAPK_KEY_PASSWD 34 | } 35 | } 36 | } 37 | 38 | buildTypes { 39 | debug { 40 | signingConfig signingConfigs.release 41 | } 42 | release { 43 | minifyEnabled true 44 | shrinkResources true 45 | signingConfig signingConfigs.release 46 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 47 | } 48 | } 49 | 50 | compileOptions { 51 | sourceCompatibility = JavaVersion.VERSION_17 52 | targetCompatibility = JavaVersion.VERSION_17 53 | } 54 | 55 | applicationVariants.configureEach { variant -> 56 | if (variant.buildType.name != "release") return 57 | outputs.forEach { 58 | def buildTypeName = variant.buildType.name 59 | def version = "$versionName-$versionCode" 60 | it.outputFileName = "WXAPK-${version}-${buildTypeName}.apk" 61 | } 62 | } 63 | } 64 | 65 | // 根据 runner action 编号生成版本号 66 | def getAppVersionCode() { 67 | def properties = new Properties() 68 | def localPropertiesFile = rootProject.file("local.properties") 69 | if (localPropertiesFile.exists()) { 70 | properties.load(new FileInputStream(localPropertiesFile)) 71 | } 72 | def version = properties.getProperty("GITHUB_RUN_NUMBER") ?: System.getenv("GITHUB_RUN_NUMBER") 73 | return version != null ? version.toInteger() : 1 74 | } 75 | 76 | // 获取最新的 tag 名称 77 | def getLastTagName() { 78 | def stdout = new ByteArrayOutputStream() 79 | exec { 80 | commandLine 'git', 'describe', '--abbrev=0', '--tags' 81 | standardOutput = stdout 82 | } 83 | return stdout.toString().trim() 84 | } 85 | 86 | tasks.register('printVersionInfo') { 87 | doLast { 88 | println "VersionName: ${getLastTagName()}, VersionCode: ${getAppVersionCode()}" 89 | } 90 | } 91 | 92 | dependencies { 93 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 94 | implementation 'androidx.documentfile:documentfile:1.0.1' 95 | implementation 'androidx.activity:activity-ktx:1.9.1' 96 | } 97 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | 9 | 16 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 93 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-playstore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twiceyuan/WXAPK/0f256781005a603b962cca9b62e6f047dd83eb66/app/src/main/ic_launcher-playstore.png -------------------------------------------------------------------------------- /app/src/main/java/com/twiceyuan/wxapk/AppFileProvider.kt: -------------------------------------------------------------------------------- 1 | package com.twiceyuan.wxapk 2 | 3 | class AppFileProvider : androidx.core.content.FileProvider() { 4 | companion object { 5 | const val AUTHORITY_SUFFIX = ".AppFileProvider" 6 | } 7 | } -------------------------------------------------------------------------------- /app/src/main/java/com/twiceyuan/wxapk/FileBrowserActivity.kt: -------------------------------------------------------------------------------- 1 | package com.twiceyuan.wxapk 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.net.Uri 6 | import android.os.Build 7 | import android.os.Bundle 8 | import android.provider.DocumentsContract 9 | import android.view.MenuItem 10 | import android.widget.ArrayAdapter 11 | import android.widget.ListView 12 | import androidx.activity.ComponentActivity 13 | import androidx.activity.result.contract.ActivityResultContract 14 | import androidx.documentfile.provider.DocumentFile 15 | 16 | class FileBrowserActivity : ComponentActivity() { 17 | 18 | private val initialUri = DocumentsContract.buildTreeDocumentUri( 19 | /* authority = */ "com.android.externalstorage.documents", 20 | /* documentId = */ "primary:Download" 21 | ) 22 | 23 | // 可能的两个微信 APK 存储路径,不是这俩就会触发选择 24 | private val wxDirUris = listOf( 25 | DocumentsContract.buildTreeDocumentUri( 26 | /* authority = */ "com.android.externalstorage.documents", 27 | /* documentId = */ "primary:Download/WeiXin" 28 | ), 29 | DocumentsContract.buildTreeDocumentUri( 30 | /* authority = */ "com.android.externalstorage.documents", 31 | /* documentId = */ "primary:Download/WeChat" 32 | ), 33 | ) 34 | 35 | private var currentDocTree: DocumentFile? = null 36 | private lateinit var listView: ListView 37 | private lateinit var adapter: ArrayAdapter 38 | 39 | private val fileNames = mutableListOf() 40 | private val fileDocs = mutableMapOf() 41 | 42 | override fun onCreate(savedInstanceState: Bundle?) { 43 | super.onCreate(savedInstanceState) 44 | setupListView() 45 | handleInitialUri() 46 | actionBar?.setDisplayHomeAsUpEnabled(true) 47 | } 48 | 49 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 50 | if (item.itemId == android.R.id.home) { 51 | finish() 52 | return true 53 | } 54 | return super.onOptionsItemSelected(item) 55 | } 56 | 57 | private fun setupListView() { 58 | listView = ListView(this) 59 | setContentView(listView) 60 | adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, fileNames) 61 | listView.adapter = adapter 62 | listView.setOnItemClickListener { _, _, position, _ -> handleItemClick(position) } 63 | } 64 | 65 | private fun handleInitialUri() { 66 | // 如果已经有权限,直接展示 67 | contentResolver.persistedUriPermissions.forEach { 68 | if (it.uri in wxDirUris) { 69 | val tree = DocumentFile.fromTreeUri(this, it.uri) ?: return 70 | displayFiles(tree) 71 | return 72 | } 73 | } 74 | 75 | // 否则触发选择路径 76 | toast(R.string.prompt_choose_apk_dir) 77 | val chooseExternalContract = getChooseExternalContract() 78 | registerForActivityResult(chooseExternalContract, activityResultRegistry) { uri -> 79 | uri ?: return@registerForActivityResult 80 | applicationContext.contentResolver.takePersistableUriPermission( 81 | uri, Intent.FLAG_GRANT_READ_URI_PERMISSION 82 | ) 83 | val tree = DocumentFile.fromTreeUri(this, uri) ?: return@registerForActivityResult 84 | displayFiles(tree) 85 | }.launch(initialUri) 86 | } 87 | 88 | private fun getChooseExternalContract() = object : ActivityResultContract() { 89 | override fun createIntent(context: Context, input: Uri?): Intent { 90 | val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply { 91 | addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) 92 | addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION) 93 | addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) 94 | if (input != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 95 | putExtra(DocumentsContract.EXTRA_INITIAL_URI, input) 96 | } 97 | } 98 | return intent 99 | } 100 | 101 | override fun parseResult(resultCode: Int, intent: Intent?): Uri? { 102 | return intent?.data 103 | } 104 | } 105 | 106 | // 处理列表点击事件 107 | private fun handleItemClick(position: Int) { 108 | if (position == 0) { 109 | navigateToParentDirectory() 110 | } else { 111 | val fileName = fileNames[position] 112 | val file = fileDocs[fileName] ?: return 113 | if (file.isFile && fileName.contains(".apk.1")) { 114 | openInstallerActivity(file) 115 | } else if (file.isDirectory) { 116 | navigateToChildDirectory(file) 117 | } else { 118 | toast(R.string.not_support_file) 119 | } 120 | } 121 | } 122 | 123 | // 返回上级目录 124 | private fun navigateToParentDirectory() { 125 | val parentFile = currentDocTree?.parentFile 126 | if (parentFile != null && parentFile.canRead() && parentFile.canWrite()) { 127 | displayFiles(parentFile) 128 | } else { 129 | toast(R.string.already_root_dir) 130 | } 131 | } 132 | 133 | private fun navigateToChildDirectory(childTree: DocumentFile) { 134 | displayFiles(childTree) 135 | } 136 | 137 | // 分发 uri 到安装器页面 138 | private fun openInstallerActivity(selectedFile: DocumentFile) { 139 | val installIntent = Intent(this, InstallerActivity::class.java).apply { 140 | data = selectedFile.uri 141 | } 142 | startActivity(installIntent) 143 | } 144 | 145 | private fun displayFiles(doc: DocumentFile) { 146 | currentDocTree = doc 147 | 148 | fileNames.clear() 149 | fileDocs.clear() 150 | 151 | fileNames.add("..") 152 | 153 | val apkRegex = Regex(".*\\.apk(\\.1){1,10}\$") 154 | doc.listFiles().forEach { 155 | val fileName = it.name ?: return@forEach 156 | val isApk = it.isFile && apkRegex.matches(fileName) 157 | fun displayName() = when { 158 | it.isDirectory -> "📁 $fileName" 159 | isApk -> "📦 $fileName" 160 | else -> error("Unknown file type") 161 | } 162 | if (it.isDirectory || isApk) { 163 | val displayName = displayName() 164 | fileNames.add(displayName) 165 | fileDocs[displayName] = it 166 | } 167 | } 168 | adapter.notifyDataSetChanged() 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /app/src/main/java/com/twiceyuan/wxapk/InstallerActivity.kt: -------------------------------------------------------------------------------- 1 | package com.twiceyuan.wxapk 2 | 3 | import android.content.BroadcastReceiver 4 | import android.content.Context 5 | import android.content.Intent 6 | import android.content.IntentFilter 7 | import android.net.Uri 8 | import android.os.Bundle 9 | import androidx.core.content.FileProvider 10 | import java.io.File 11 | import java.io.FileOutputStream 12 | 13 | 14 | /** 15 | * Created by twiceYuan on 2018/3/5. 16 | * 17 | * 安装意图分发 apk.1 -> apk installer 18 | */ 19 | class InstallerActivity : PermissionHandlerActivity() { 20 | 21 | override fun onCreate(savedInstanceState: Bundle?) { 22 | super.onCreate(savedInstanceState) 23 | 24 | registerInstallReceiver() 25 | 26 | intent?.data?.let { install(it) } 27 | } 28 | 29 | // 注册安装结束的事件监听,用于清除缓存文件 30 | private fun registerInstallReceiver() { 31 | val intentFilter = IntentFilter() 32 | intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED) 33 | intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED) 34 | intentFilter.addDataScheme("package") 35 | applicationContext.registerReceiver(object : BroadcastReceiver() { 36 | override fun onReceive(context: Context?, intent: Intent?) { 37 | val applicationContext = context?.applicationContext ?: return 38 | applicationContext.unregisterReceiver(this) 39 | applicationContext.getExternalFilesDir(TEMP_APK_PATH) 40 | ?.listFiles() 41 | ?.forEach { it.delete() } 42 | } 43 | }, intentFilter) 44 | } 45 | 46 | override fun onNewIntent(intent: Intent?) { 47 | super.onNewIntent(intent) 48 | 49 | val uri = intent?.data 50 | if (uri != null) { 51 | install(uri) 52 | } else { 53 | finish() 54 | } 55 | } 56 | 57 | private fun install(paramUri: Uri) { 58 | fun installAction(uri: Uri) { 59 | val installerIntent = Intent(Intent.ACTION_VIEW) 60 | installerIntent.setDataAndType(uri, "application/vnd.android.package-archive") 61 | installerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 62 | installerIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) 63 | startActivity(installerIntent) 64 | finish() 65 | } 66 | 67 | when (paramUri.scheme) { 68 | "file" -> { 69 | // 微信 7.0 以下使用的是 file uri,需要申请文件读取权限才能读取创建临时文件 70 | requestStorageReadPermission { installAction(paramUri) } 71 | } 72 | 73 | "content" -> { 74 | // 拷贝内沙盒中提供 Uri,避免使用文件权限 75 | val newUri = paramUri.convertToInsideUri() ?: return 76 | installAction(newUri) 77 | } 78 | } 79 | } 80 | 81 | // 转换为内部文件的 Uri,方便进行改名 82 | private fun Uri.convertToInsideUri(): Uri? { 83 | val inputStream = contentResolver.openInputStream(this) ?: return null 84 | val tempDir = getExternalFilesDir(TEMP_APK_PATH) ?: return null 85 | val tempApkFile = 86 | File.createTempFile(Uri.encode(lastPathSegment) ?: "temp", ".apk", tempDir) 87 | val outputStream = FileOutputStream(tempApkFile) 88 | inputStream.copyTo(outputStream) 89 | inputStream.close() 90 | val authority = packageName + AppFileProvider.AUTHORITY_SUFFIX 91 | return FileProvider.getUriForFile(this@InstallerActivity, authority, tempApkFile) 92 | } 93 | 94 | companion object { 95 | const val TEMP_APK_PATH = "temp_apk" 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/com/twiceyuan/wxapk/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.twiceyuan.wxapk 2 | 3 | import android.app.Activity 4 | import android.content.ComponentName 5 | import android.content.Intent 6 | import android.content.pm.PackageManager 7 | import android.os.Bundle 8 | import android.view.View 9 | import com.twiceyuan.wxapk.databinding.ActivityMainBinding 10 | 11 | open class MainActivity : Activity() { 12 | 13 | private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) } 14 | 15 | override fun onCreate(savedInstanceState: Bundle?) { 16 | super.onCreate(savedInstanceState) 17 | setContentView(binding.root) 18 | 19 | setupVisibleInLauncher() 20 | } 21 | 22 | private fun setupVisibleInLauncher() { 23 | val componentName = ComponentName(this, MainActivity::class.java) 24 | val setting = packageManager.getComponentEnabledSetting(componentName) 25 | 26 | val isHidden = setting == PackageManager.COMPONENT_ENABLED_STATE_DISABLED 27 | 28 | fun toggleComponentEnable() = when (isHidden) { 29 | true -> packageManager.setComponentEnabledSetting( 30 | componentName, 31 | PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 32 | PackageManager.DONT_KILL_APP 33 | ) 34 | 35 | false -> packageManager.setComponentEnabledSetting( 36 | componentName, 37 | PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 38 | PackageManager.DONT_KILL_APP 39 | ) 40 | } 41 | 42 | val onClickListener: (View) -> Unit = { 43 | toggleComponentEnable() 44 | toast(R.string.set_success) 45 | this.finish() 46 | } 47 | 48 | // 展示之前的状态,是否已被隐藏 49 | binding.apply { 50 | switchHideIcon.isChecked = isHidden 51 | switchHideIcon.setOnClickListener(onClickListener) 52 | layoutHideIcon.setOnClickListener(onClickListener) 53 | } 54 | 55 | binding.layoutFileBrowser.setOnClickListener { 56 | startActivity(Intent(this, FileBrowserActivity::class.java)) 57 | } 58 | 59 | binding.layoutFileBrowser.setOnLongClickListener { 60 | applicationContext.contentResolver.persistedUriPermissions.forEach { 61 | applicationContext.contentResolver.releasePersistableUriPermission( 62 | it.uri, 63 | Intent.FLAG_GRANT_READ_URI_PERMISSION 64 | ) 65 | } 66 | startActivity(Intent(this, FileBrowserActivity::class.java)) 67 | true 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/twiceyuan/wxapk/PermissionHandlerActivity.kt: -------------------------------------------------------------------------------- 1 | package com.twiceyuan.wxapk 2 | 3 | import android.Manifest 4 | import android.annotation.SuppressLint 5 | import android.app.Activity 6 | import android.content.pm.PackageManager 7 | import android.os.Build 8 | 9 | /** 10 | * 权限请求的封装 11 | */ 12 | @SuppressLint("Registered") 13 | open class PermissionHandlerActivity : Activity() { 14 | 15 | private var permissionRequestCallback: (() -> Unit)? = null 16 | 17 | fun requestStorageReadPermission(grantedCallback: () -> Unit) { 18 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 19 | permissionRequestCallback = grantedCallback 20 | requestPermissions(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), grantedCallback.hashCode()) 21 | } else { 22 | grantedCallback() 23 | } 24 | } 25 | 26 | override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { 27 | super.onRequestPermissionsResult(requestCode, permissions, grantResults) 28 | if (permissionRequestCallback?.hashCode() != requestCode) return 29 | 30 | if (grantResults.isEmpty() || grantResults[0] != PackageManager.PERMISSION_GRANTED) { 31 | toast(R.string.storage_permission_denied_tip) 32 | finish() 33 | return 34 | } 35 | 36 | permissionRequestCallback?.invoke() 37 | } 38 | } -------------------------------------------------------------------------------- /app/src/main/java/com/twiceyuan/wxapk/ShadowActivity.kt: -------------------------------------------------------------------------------- 1 | package com.twiceyuan.wxapk 2 | 3 | class ShadowActivity: MainActivity() -------------------------------------------------------------------------------- /app/src/main/java/com/twiceyuan/wxapk/ToastExt.kt: -------------------------------------------------------------------------------- 1 | package com.twiceyuan.wxapk 2 | 3 | import android.content.Context 4 | import android.widget.Toast 5 | 6 | fun Context.toast(resId: Int) { 7 | Toast.makeText(applicationContext, resId, Toast.LENGTH_SHORT).show() 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 18 | 19 | 22 | 23 | 30 | 31 | 37 | 38 | 41 | 42 | 46 | 47 | 51 | 52 | 59 | 60 | 63 | 64 | 71 | 72 | 73 | 74 | 81 | 82 | 83 | 84 | 90 | 91 | 96 | 97 | 104 | 105 | 108 | 109 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twiceyuan/WXAPK/0f256781005a603b962cca9b62e6f047dd83eb66/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twiceyuan/WXAPK/0f256781005a603b962cca9b62e6f047dd83eb66/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twiceyuan/WXAPK/0f256781005a603b962cca9b62e6f047dd83eb66/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20dp 4 | 16dp 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #626D72 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/keys.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | com.twiceyuan.wxapk.FileProvider 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | APK.1安装器 3 | 直接在微信中打开接收到的 APK 即可 4 | 显示 Launcher 图标 5 | 隐藏 Launcher 图标 6 | 设置成功,因机型差异可能会稍后生效 7 | 在低版本上需要存储权限才能正常使用 8 | 使用方式 9 | 在微信中打开接收到的 APK 文件即可 10 | 在启动器中隐藏本应用的图标 11 | hide_launcher_icon 12 | 隐藏图标 13 | 浏览文件 14 | 浏览设备上的 APK.1 文件,长按重新选择目录 15 | 已经是根目录 16 | 请授权读取 apk.1 文件目录,一般是 WeiXin 或 WeChat 17 | 不支持的文件格式 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/xml/file_paths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /app/src/test/java/com/twiceyuan/wxapk/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.twiceyuan.wxapk 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '2.0.0' 5 | repositories { 6 | google() 7 | mavenCentral() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:8.1.4' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | mavenCentral() 22 | maven { url 'https://jitpack.io' } 23 | } 24 | } 25 | 26 | tasks.register('clean', Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | android.useAndroidX=true 13 | org.gradle.jvmargs=-Xmx1536m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twiceyuan/WXAPK/0f256781005a603b962cca9b62e6f047dd83eb66/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon May 05 22:31:58 CST 2025 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------