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