1

I want to use receiver for auto-update.

When clicking, get download using the URI.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(strUrl));
startActivity(intent);

And What i want is to run the apk which is downloaded by the intent automatically.

Now, I have to click the apk file one more after download. but I want to do automatically download - run new Apk - delete apk file.

So I'm trying to use receiver but I don't know how to use it.

1st, I added this in manifest.

 <receiver android:name=".common.PackageReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <action android:name="android.intent.action.PACKAGE_REMOVED" />
        <action android:name="android.intent.action.PACKAGE_REPLACED" />
        <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
       <data android:scheme="package" /> 
    </intent-filter>
</receiver>

2nd, I make new class.

package com.ezcaretech.ecf.common;
public class PackageReceiver extends BroadcastReceiver {

public static final String DOWNLOAD_COMPLETE = "android.intent.action.DOWNLOAD_COMPLETE";

@Override
public void onReceive(Context context, Intent intent) {
    String packageName = intent.getData().getSchemeSpecificPart();
    String action = intent.getAction();

    if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        Log.d("TAG", "DOWNLOAD COMPLETE");
    }
  }
}

But, after download, the receiver doesn't work anymore.

Thanks

Adrian
  • 301
  • 4
  • 15

2 Answers2

0

You have statically registered the BroadcastReceiver which guarantees that your app will be started when any of those intents you posted is sent.

However, your receiver is only doing something when it gets

DownloadManager.ACTION_DOWNLOAD_COMPLETE

J_Strauton
  • 2,270
  • 3
  • 28
  • 70
0

Thanks guys. I change my code

builder.setPositiveButton(R.string.kor_confirm, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
            DownloadManager dm= (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(strUrl));
            dm.enqueue(request);
        }
    });`

and It is working well. Thanks All

Adrian
  • 301
  • 4
  • 15