-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09d995e
commit 823ae8f
Showing
5 changed files
with
449 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/java/dev/brahmkshatriya/echo/ExtensionOpenerActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package dev.brahmkshatriya.echo | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.widget.Toast | ||
import androidx.core.net.toFile | ||
import androidx.core.net.toUri | ||
import androidx.fragment.app.FragmentActivity | ||
import dev.brahmkshatriya.echo.ui.extension.ApkLinkParser | ||
import java.io.File | ||
|
||
|
||
class ExtensionOpenerActivity : Activity() { | ||
override fun onStart() { | ||
super.onStart() | ||
val uri = intent.data | ||
val file = when (uri?.scheme) { | ||
"content" -> getTempFile(uri) | ||
else -> null | ||
} | ||
finish() | ||
if (file == null) | ||
Toast.makeText(this, "Could not find a file.", Toast.LENGTH_SHORT).show() | ||
val startIntent = Intent(this, MainActivity::class.java) | ||
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
startIntent.data = file?.let { Uri.fromFile(it) } | ||
startActivity(startIntent) | ||
} | ||
|
||
private fun getTempFile(uri: Uri): File? { | ||
val stream = contentResolver.openInputStream(uri) ?: return null | ||
val bytes = stream.readBytes() | ||
val tempFile = File.createTempFile("temp", ".apk", cacheDir) | ||
tempFile.writeBytes(bytes) | ||
return tempFile | ||
} | ||
|
||
companion object { | ||
const val EXTENSION_INSTALLER = "extensionInstaller" | ||
fun FragmentActivity.openExtensionInstaller(uri: Uri) { | ||
val apk = uri.toFile() | ||
val supportedLinks = ApkLinkParser.getSupportedLinks(apk) | ||
|
||
|
||
supportFragmentManager.setFragmentResultListener(EXTENSION_INSTALLER, this) { _, bundle -> | ||
val file = bundle.getString("file")?.toUri()?.toFile() | ||
file?.delete() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.