添加下载状态通知功能
This commit is contained in:
@ -0,0 +1,60 @@
|
||||
package com.gh.gamecenter.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.gh.common.util.PackageUtils;
|
||||
import com.gh.common.util.RunningUtils;
|
||||
import com.gh.gamecenter.DownloadManagerActivity;
|
||||
import com.gh.gamecenter.SplashScreenActivity;
|
||||
import com.gh.gamecenter.eventbus.EBMiPush;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by LGT on 2016/10/10.
|
||||
*/
|
||||
public class InstallReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String path = intent.getStringExtra("path");
|
||||
if (PackageUtils.isCanLaunchSetup(context, path)) {
|
||||
context.startActivity(PackageUtils.getInstallIntent(path));
|
||||
} else {
|
||||
if (RunningUtils.isRunning(context)) {
|
||||
if (RunningUtils.isEqualsTop(context, DownloadManagerActivity.class.getName())) {
|
||||
// 这里是指从后台返回到前台 前两个的是关键
|
||||
Intent intent2 = new Intent();
|
||||
intent2.setAction(Intent.ACTION_MAIN);
|
||||
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent2.setComponent(new ComponentName(context, DownloadManagerActivity.class));
|
||||
intent2.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
|
||||
| Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
|
||||
context.startActivity(intent2);
|
||||
EventBus.getDefault().post(new EBMiPush("plugin_install", path));
|
||||
} else {
|
||||
Intent intent2 = new Intent(context,
|
||||
DownloadManagerActivity.class);
|
||||
intent2.putExtra("currentItem", 0);
|
||||
intent2.putExtra("path", path);
|
||||
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent2);
|
||||
}
|
||||
} else {
|
||||
// 应用未在运行
|
||||
Intent intent2 = new Intent(context, SplashScreenActivity.class);
|
||||
intent2.setAction(Intent.ACTION_MAIN);
|
||||
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
intent2.putExtra("from", "plugin_install");
|
||||
intent2.putExtra("path", path);
|
||||
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(intent2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user