| | |
| | | import com.alibaba.baichuan.android.trade.AlibcTradeSDK; |
| | | import com.alibaba.baichuan.android.trade.callback.AlibcTradeInitCallback; |
| | | import com.alibaba.baichuan.trade.biz.core.taoke.AlibcTaokeParams; |
| | | import com.google.gson.Gson; |
| | | import com.huawei.android.hms.agent.HMSAgent; |
| | | import com.huawei.android.hms.agent.common.handler.ConnectHandler; |
| | | import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator; |
| | | import com.qq.e.ads.splash.SplashAD; |
| | | import com.qq.e.ads.splash.SplashADListener; |
| | | import com.qq.e.comm.managers.GDTADManager; |
| | | import com.qq.e.comm.util.AdError; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.wpc.library.okhttp.OkHttpUtils; |
| | |
| | | import com.yeshi.ec.rebate.myapplication.BuXinConstant; |
| | | import com.yeshi.ec.rebate.myapplication.R; |
| | | import com.yeshi.ec.rebate.myapplication.ShoppingApi; |
| | | import com.yeshi.ec.rebate.myapplication.entity.user.GDTAdInfo; |
| | | import com.yeshi.ec.rebate.myapplication.ui.guidepages.GuidePages; |
| | | import com.yeshi.ec.rebate.myapplication.ui.main.MainActivity; |
| | | import com.yeshi.ec.rebate.myapplication.util.AdUtil; |
| | | import com.yeshi.ec.rebate.myapplication.util.Constant; |
| | | import com.yeshi.ec.rebate.myapplication.util.PermissionsActivity; |
| | | import com.yeshi.ec.rebate.myapplication.util.PermissionsChecker; |
| | |
| | | } |
| | | |
| | | private void loadAD() { |
| | | GDTAdInfo adInfo = AdUtil.getGDTADInfo(getApplicationContext()); |
| | | if (adInfo == null) { |
| | | return; |
| | | } |
| | | |
| | | if (Build.VERSION.SDK_INT >= 23) { |
| | | checkAndRequestPermission(); |
| | | checkAndRequestPermission(adInfo.getSplashPid()); |
| | | } else { |
| | | // 如果是Android6.0以下的机器,默认在安装时获得了所有权限,可以直接调用SDK |
| | | fetchSplashAD(this, container, skipView, getPosId(), this, 0); |
| | | fetchSplashAD(this, container, skipView, adInfo.getSplashPid(), this, 0); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | private String getPosId() { |
| | | String posId = getIntent().getStringExtra("pos_id"); |
| | | return TextUtils.isEmpty(posId) ? "6071718323622945" : posId; |
| | | } |
| | | |
| | | /** |
| | | * ----------非常重要---------- |
| | | * <p> |
| | |
| | | * 注意:下面的`checkSelfPermission`和`requestPermissions`方法都是在Android6.0的SDK中增加的API,如果您的App还没有适配到Android6.0以上,则不需要调用这些方法,直接调用广点通SDK即可。 |
| | | */ |
| | | @TargetApi(Build.VERSION_CODES.M) |
| | | private void checkAndRequestPermission() { |
| | | private void checkAndRequestPermission(String pid) { |
| | | List<String> lackedPermission = new ArrayList<String>(); |
| | | if (!(checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)) { |
| | | lackedPermission.add(Manifest.permission.READ_PHONE_STATE); |
| | |
| | | |
| | | // 权限都已经有了,那么直接调用SDK |
| | | if (lackedPermission.size() == 0) { |
| | | fetchSplashAD(this, container, skipView, getPosId(), this, 0); |
| | | fetchSplashAD(this, container, skipView, pid, this, 0); |
| | | } else { |
| | | // 请求所缺少的权限,在onRequestPermissionsResult中再看是否获得权限,如果获得权限就可以调用SDK,否则不要调用SDK。 |
| | | String[] requestPermissions = new String[lackedPermission.size()]; |
| | |
| | | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { |
| | | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| | | if (requestCode == 1024 && hasAllPermissionsGranted(grantResults)) { |
| | | fetchSplashAD(this, container, skipView, getPosId(), this, 0); |
| | | GDTAdInfo adInfo = AdUtil.getGDTADInfo(getApplicationContext()); |
| | | if(adInfo==null) |
| | | return; |
| | | fetchSplashAD(this, container, skipView, adInfo.getSplashPid(), this, 0); |
| | | } else { |
| | | // 如果用户没有授权,那么应该说明意图,引导用户去设置里面授权。 |
| | | Toast.makeText(this, "应用缺少必要的权限!请点击\"权限\",打开所需要的权限。", Toast.LENGTH_LONG).show(); |
| | |
| | | } |
| | | }, 2000); |
| | | } else {//不需要显示引导页 |
| | | loadAD(); |
| | | |
| | | //请求广告是否需要显示 |
| | | ShoppingApi.getSplashAdConfig(getApplicationContext(), new BasicTextHttpResponseHandler() { |
| | | @Override |
| | |
| | | if (jsonObject.optInt("code") == 0) { |
| | | JSONObject data = jsonObject.optJSONObject("data"); |
| | | if (data.optBoolean("show")) {//显示广告 |
| | | iv_splash.postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | showAd(); |
| | | } |
| | | }, 2000); |
| | | JSONObject ad = data.optJSONObject("ad"); |
| | | GDTAdInfo info = new Gson().fromJson(ad.toString(), GDTAdInfo.class); |
| | | if (info != null) { |
| | | AdUtil.saveGDTADInfo(getApplicationContext(), info); |
| | | GDTADManager.getInstance().initWith(SplashActivity.this, info.getAppId()); |
| | | loadAD(); |
| | | iv_splash.postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | showAd(); |
| | | } |
| | | }, 2000); |
| | | } else { |
| | | //延时2s跳转 |
| | | iv_splash.postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | jumpMainActivity(); |
| | | } |
| | | }, 2000); |
| | | } |
| | | } else {//不显示 |
| | | //延时2s跳转 |
| | | iv_splash.postDelayed(new Runnable() { |