Как я могу открыть файл APK в приложении Expo (SDK 52)?Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как я могу открыть файл APK в приложении Expo (SDK 52)?

Сообщение Anonymous »

Я пытаюсь открыть файл .apk в моем приложении Expo, но после загрузки его просто ничего не делает. Я попытался использовать намерения с изображениями, видео и аудионами, и это работает, кроме как с файлами APK. Я использую сборку разработки, поэтому я не использую Expo Go. < /P>
import * as FileSystem from "expo-file-system";
import { startActivityAsync } from 'expo-intent-launcher';

export default function HomeScreen() {

const downloadAndInstallApk = async () => {
const url = "https://premium.apk.aptoide.com/aptoide ... 25ca33.apk";

try {
const fileUri = FileSystem.cacheDirectory + "com-zhiliaoapp-musically-go-300702-65618975-98c804aab2784f318a912d822925ca33.apk";

const contentUri = await FileSystem.getContentUriAsync(uri);
console.log("Content URI:", contentUri);

if (Platform.OS === "android") {
// Launch the installer with the proper action
await startActivityAsync("android.intent.action.INSTALL_PACKAGE", {
data: contentUri,
flags: 1, // Grant temporary read permission
});
} else {
console.error("This functionality is only available on Android.");
}
} catch (error) {
console.error("Error downloading or installing APK:", error);
}
};

// The same code but using images. This actually works.
const downloadAndInstallApkImage = async () => {
const url = "https://file-examples.com/storage/fe214 ... 2500kB.jpg";
try {
const fileUri = FileSystem.documentDirectory + "file_example_JPG_2500kB.jpg";
// Download the file
const { uri } = await FileSystem.downloadAsync(url, fileUri);
console.log("Downloaded to:", uri);

// Convert file:// URI to a content:// URI
const contentUri = await FileSystem.getContentUriAsync(uri);
console.log("Content URI:", contentUri);

if (Platform.OS === "android") {
// Launch the installer with the proper action
await startActivityAsync("android.intent.action.VIEW", {
data: contentUri,
flags: 1, // Grant temporary read permission
});
} else {
console.error("This functionality is only available on Android.");
}
} catch (error) {
console.error("Error downloading or installing APK:", error);
}
};
}


Подробнее здесь: https://stackoverflow.com/questions/794 ... app-sdk-52
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»