Я пытаюсь открыть файл .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
Как я могу открыть файл APK в приложении Expo (SDK 52)? ⇐ Android
Форум для тех, кто программирует под Android
-
Anonymous
1739760630
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-web/com-zhiliaoapp-musically-go-300702-65618975-98c804aab2784f318a912d822925ca33.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/fe21422a6d67aa28993b797/2017/10/file_example_JPG_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);
}
};
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79441854/how-can-i-open-an-apk-file-within-expo-app-sdk-52[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия