2012-02-10 34 views
6

Tôi có thể cài đặt một tập tin APK được lưu trữ trên sdcard sử dụng đoạn mã sau:Android làm thế nào để cài đặt tập tin APK được lưu trữ trong thư mục tài sản

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/downloads/Sample.apk")), "application/vnd.android.package-archive"); 
startActivity(intent); 

Làm thế nào tôi có thể cài đặt một tập tin APK được lưu trữ trong thư mục tài sản? Có thể không?

Trả lời

9

sử dụng mã sau đây để ghi file vào sdcard: How to copy files from 'assets' folder to sdcard? và từ con đường đó cài đặt bằng cách làm theo:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/download/" + "app.apk")), "application/vnd.android.package-archive"); 
startActivity(intent); 
+0

Cảm ơn bro .. ý tưởng tốt đẹp nó hoạt động tuyệt vời !!! – Sandy

+4

Whats điều kiện khi điện thoại không có sdcard nhưng chỉ có bộ nhớ trong? –

+0

Tôi tin rằng các điểm gọi đến/sdcard - bộ nhớ trong – Clocker

Các vấn đề liên quan