| | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONObject; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.appcompat.app.AppCompatActivity; |
| | | import androidx.core.app.ActivityCompat; |
| | | import androidx.core.content.ContextCompat; |
| | | |
| | | import static android.content.pm.PackageManager.PERMISSION_DENIED; |
| | | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| | | |
| | | public class SplashActivity extends AppCompatActivity { |
| | |
| | | SharedPreferences sharedPreferences = getSharedPreferences("permission", Context.MODE_PRIVATE); |
| | | boolean showPermission = sharedPreferences.getBoolean("show", true); |
| | | |
| | | // if (1 > 0) { |
| | | // toMainActivity(); |
| | | // return; |
| | | // } |
| | | |
| | | |
| | | if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PERMISSION_GRANTED && showPermission) { |
| | | ActivityCompat.requestPermissions(this, PERMISSIONS, REQUEST_CODE); |
| | | } else { |
| | | MyApplication.init(MyApplication.application, new MyApplication.InitListener() { |
| | | @Override |
| | | public void onFinish() { |
| | | next(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | }); |
| | | int delayMs = 1; |
| | | |
| | | void next() { |
| | | MyApplication.init(MyApplication.application, new MyApplication.InitListener() { |
| | | @Override |
| | | public void onFinish() { |
| | | |
| | | } |
| | | }); |
| | | |
| | | if (1 > 0) { |
| | | vg_ad.postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | HttpApiUtil.getConfig(getApplicationContext(), new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject != null) { |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | JSONObject data = jsonObject.getJSONObject("Data"); |
| | | JSONObject ad = data.optJSONObject("adNew"); |
| | | //浏览器外跳协议 |
| | | AppConfigUtil.saveBrowserJumpOutProtocolPrefix(getApplicationContext(), data.optString("jumpAppProtocolPrefix")); |
| | | //保存联系客服,注销链接 |
| | | AppConfigUtil.saveConcatUsLink(getApplicationContext(), data.optString("contactUsLink")); |
| | | AppConfigUtil.saveUnRegisterLink(getApplicationContext(), data.optString("unRegisterLink")); |
| | | AdUtil.saveAdConfig(getApplicationContext(), ad); |
| | | MyApplication.initAd(MyApplication.application, new MyApplication.InitListener() { |
| | | @Override |
| | | public void onFinish() { |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | loadSplashAd(); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | loadSplashAd(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, throwable); |
| | | loadSplashAd(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | toMainActivity(); |
| | | } |
| | | }, delayMs); |
| | | },3000); |
| | | |
| | | |
| | | return; |
| | | } |
| | | |
| | | |
| | | int delayMs = 1; |
| | | vg_ad.postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | HttpApiUtil.getConfig(getApplicationContext(), new BasicTextHttpResponseHandler() { |
| | | |
| | | @Override |
| | | public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { |
| | | if (jsonObject != null) { |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | JSONObject data = jsonObject.getJSONObject("Data"); |
| | | JSONObject ad = data.optJSONObject("adNew"); |
| | | //浏览器外跳协议 |
| | | AppConfigUtil.saveBrowserJumpOutProtocolPrefix(getApplicationContext(), data.optString("jumpAppProtocolPrefix")); |
| | | //保存联系客服,注销链接 |
| | | AppConfigUtil.saveConcatUsLink(getApplicationContext(), data.optString("contactUsLink")); |
| | | AppConfigUtil.saveUnRegisterLink(getApplicationContext(), data.optString("unRegisterLink")); |
| | | AdUtil.saveAdConfig(getApplicationContext(), ad); |
| | | MyApplication.initAd(MyApplication.application, new MyApplication.InitListener() { |
| | | @Override |
| | | public void onFinish() { |
| | | runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | loadSplashAd(); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | loadSplashAd(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, throwable); |
| | | loadSplashAd(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | }, delayMs); |
| | | } |
| | | |
| | | |
| | |
| | | * 加载开屏广告 |
| | | */ |
| | | private void loadSplashAd() { |
| | | |
| | | AdUtil.AD_TYPE splashType = AdUtil.getAdType(getApplicationContext(), ""); |
| | | if (splashType == null) { |
| | | vg_ad.postDelayed(new Runnable() { |
| | |
| | | finish(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| | | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| | | if (requestCode == REQUEST_CODE) { |
| | | for (int i = 0; i < permissions.length; i++) { |
| | | if (grantResults[i] == PERMISSION_GRANTED) {//选择了“始终允许” |
| | | requetPermission(); |
| | | } else { |
| | | //拒绝了授权 |
| | | if (grantResults[i] == PERMISSION_DENIED) { |
| | | SharedPreferences sharedPreferences = getSharedPreferences("permission", Context.MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sharedPreferences.edit(); |
| | | editor.putBoolean("show", false); |
| | | editor.commit(); |
| | | } |
| | | next(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |