Daftar dan Belajar Sekarang!

Error receiving broadcast Intent

foto gustiErl
1 Kontribusi 0 Coto
1 minggu yang lalu
Pagi agan2, mau tanya saya mau buat auto update apklikasi jika file .apknya sudah terdownload untuk downloadnya suda berhasil tapi untuk update installasinya engga bisa, langsung force close aplikasi, targetSDKnya 28 dan Smartphone saya suda os Oreo. ini funsi update saya :
public void Update() {
        String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
        String fileName = "bakul.apk";
        destination += fileName;
        final Uri uri = Uri.parse("file://" + destination);

        //Delete update file if exists
        File file = new File(destination);
        if (file.exists())
            //file.delete() - test this, I think sometimes it doesnt work
            file.delete();

        //get url of app on server
        final String url = "http://192.168.87.87.com/bakul.apk";

        //set downloadmanager
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));

        //set destination
        request.setDestinationUri(uri);


        // get download service and enqueue file
        final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
        final long downloadId = manager.enqueue(request);

        //set BroadcastReceiver to install app when .apk is downloaded
        BroadcastReceiver onComplete = new BroadcastReceiver() {
            public void onReceive(Context ctxt, Intent intent) {
                Intent install = new Intent(Intent.ACTION_VIEW);
                install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                install.setDataAndType(uri,"application/vnd.android.package-archive");
                startActivity(install);
                unregisterReceiver(this);
                finish();
            }
        };
        //register receiver for when .apk download is compete
        registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    }

Jawaban
foto IfanZalukhu
91 Kontribusi 57 Coto
1 minggu yang lalu
Error logcat nya bagaimana gan? Kalau tidak salah, untuk otomatis update kalau ada peningkatan versi wajib melalui "build.gradle" level app nya. Kita tambah/increase "versionCode" nya yang sebelumnya dari 1, jadi dua. mungkin link ini bisa membantu : Version your app


Login untuk diksusi di forum sekolah koding