赞
踩
我总结一下,ss/ssr的目的就是用来翻q的,侧重于流量混淆加密,穿透防火q是第一位,使用socket5代理。而vpn的目的是用来加密企业数据的,安全是第一位,本意并非是翻q
对于vpn来说安全是第一位的,而对于ss/ssr来说穿透防火q是第一位,抗干扰性强,而且对流量做了混淆,(所有流量在通过防火q的时候,基本上都被识别为普通流量,也就是说你翻q了,但是相关部门是检测不到你在翻q的。)两者的出发点和着重点就不同,ss/ssr更注重流量的混淆加密。
参考文章
注意内存泄漏问题
AdMob 是移动电话广告市场,可提供用户在移动电话网络上播放广告。2006年创建,2009年被谷歌收购。
Admob覆盖200多个国家,是美国最大的手机广告平台。
这里建议看官方文档,非常详细,几乎是傻瓜式教学。点这里进入官方文档
我这里说一下我一开始遇到的两个坑,都很简单,但是我当时没注意到
一开始我一直在纠结这个报错,后来才发现,AdRequest
后面不用加括号。也算长个记性吧
这里一共有两个id,一个id是应用级id,是加在Manifest文件中的,另外一个id是控件级id,是加在控件的属性上的。
前者是
后者是
官方文档说的测试id,是后者,而不是Manifest中的
我在广告控件里加了个TextView
效果如下
上面是横幅广告,是谷歌官方推荐新手学的,我用的是插页式广告。我把官方文档的demo摘取下来了。在这里我把他分析一下
xml中还是官方文档当中的布局,我这里只显示MainActivity中的
布局是这样的,最上面是广告,下面有个TextView
,左下角是个Button
,右下角是个TextView
大体流程是这样:首先启动Activity
,执行生命周期函数,然后在onCreate
中进行初始化和广告对象InterstitialAd
的赋值,然后利用倒计时工具CountDownTimer
,倒计时3s后(期间右下角的TextView
会更新剩余时间,从3s开始,直到0s),左边的Button
才显示出来。点击Button
的时候,会先判断广告对象是否为null
,如果不为null
,就显示广告,如果为null
,就重新加载广告,然后倒计时3s,结束后,显示按钮。
在这里我做了个测试,就是切换到广告页面和切回MainActivity
,发现分别调用了onPause
和onResume
。所以我猜测,广告页面不是新的Activity
,切回的时候,会调用Activity
的生命周期函数onResume
执行效果如下
执行过程中,日志打印以及分析如下
切回MainActivity
的时候,广告对象InterstitialAd
又为null
了。我猜测是调用广告页面的时候,即调用show
方法的时候,会对广告对象赋值为null
。
MainActivity的完整代码如下
package com.example.mypreworktest; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.os.CountDownTimer; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.ads.AdError; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView; import com.google.android.gms.ads.FullScreenContentCallback; import com.google.android.gms.ads.LoadAdError; import com.google.android.gms.ads.MobileAds; import com.google.android.gms.ads.initialization.InitializationStatus; import com.google.android.gms.ads.initialization.OnInitializationCompleteListener; import com.google.android.gms.ads.interstitial.InterstitialAd; import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback; public class MainActivity extends AppCompatActivity { private static final String TAG = "MyActivity"; private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/1033173712"; private static final long GAME_LENGTH_MILLISECONDS = 3000;//总时长 private InterstitialAd interstitialAd; private CountDownTimer countDownTimer; private Button retryButton; private boolean gameIsInProgress; private long timerMilliseconds; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.i(TAG, "onCreate"); // Initialize the Mobile Ads SDK. MobileAds.initialize(this, new OnInitializationCompleteListener() { @Override public void onInitializationComplete(InitializationStatus initializationStatus) {} }); loadAd(); // Create the "retry" button, which tries to show an interstitial between game plays. retryButton = findViewById(R.id.retry_button); retryButton.setVisibility(View.INVISIBLE); retryButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showInterstitial(); } }); startGame(); } public void loadAd() { AdRequest adRequest = new AdRequest.Builder().build(); //插页广告 加载 InterstitialAd.load( this, AD_UNIT_ID, adRequest, new InterstitialAdLoadCallback() { @Override public void onAdLoaded(@NonNull InterstitialAd interstitialAd) { // The mInterstitialAd reference will be null until // an ad is loaded. // 翻译: 在此之前,interstitialAd都为null,此时才被加载 MainActivity.this.interstitialAd = interstitialAd; Log.i(TAG, "onAdLoaded"); Toast.makeText(MainActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show(); //FullScreenContentCallback 处理与展示 InterstitialAd 相关的事件 interstitialAd.setFullScreenContentCallback( new FullScreenContentCallback() { @Override public void onAdDismissedFullScreenContent() { // Called when fullscreen content is dismissed. // Make sure to set your reference to null so you don't show it a second time. // 翻译: 确保将引用设置为null,这样就不会再次显示它 MainActivity.this.interstitialAd = null; Log.d("TAG", "The ad was dismissed."); } @Override public void onAdFailedToShowFullScreenContent(AdError adError) { // Called when fullscreen content failed to show. // Make sure to set your reference to null so you don't // show it a second time. //翻译: 同上 MainActivity.this.interstitialAd = null; Log.d("TAG", "The ad failed to show."); } @Override public void onAdShowedFullScreenContent() { // Called when fullscreen content is shown. Log.d("TAG", "The ad was shown."); } }); } @Override public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) { // Handle the error Log.i(TAG, loadAdError.getMessage()); interstitialAd = null; String error = String.format( "domain: %s, code: %d, message: %s", loadAdError.getDomain(), loadAdError.getCode(), loadAdError.getMessage()); Toast.makeText( MainActivity.this, "onAdFailedToLoad() with error: " + error, Toast.LENGTH_SHORT) .show(); } }); } private void createTimer(final long milliseconds) { // Create the game timer, which counts down to the end of the level // and shows the "retry" button. //翻译: 它倒计时到级别的末尾,并显示“重试”按钮。 if (countDownTimer != null) { countDownTimer.cancel(); } final TextView textView = findViewById(R.id.timer); countDownTimer = new CountDownTimer(milliseconds, 1000) { @Override public void onTick(long millisUnitFinished) { timerMilliseconds = millisUnitFinished; Log.i(TAG, millisUnitFinished + "ms"); textView.setText("seconds remaining: " + ((millisUnitFinished / 1000) + 1)); } @Override public void onFinish() { gameIsInProgress = false; textView.setText("done!"); retryButton.setVisibility(View.VISIBLE); } }; } @Override protected void onStart() { Log.i(TAG, "onStart"); super.onStart(); } @Override protected void onRestart() { Log.i(TAG, "onRestart"); super.onRestart(); } @Override public void onResume() { // Start or resume the game. super.onResume(); Log.i(TAG, "onResume,此时广告为: "+ interstitialAd); if (gameIsInProgress) { resumeGame(timerMilliseconds); } } @Override public void onPause() { // Cancel the timer if the game is paused. Log.i(TAG, "onPause"); countDownTimer.cancel(); super.onPause(); } private void showInterstitial() { // Show the ad if it's ready. Otherwise toast and restart the game. if (interstitialAd != null) { interstitialAd.show(this); } else { Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show(); startGame(); } } private void startGame() { // Request a new ad if one isn't already loaded, hide the button, and kick off the timer. if (interstitialAd == null) { loadAd(); } retryButton.setVisibility(View.INVISIBLE); resumeGame(GAME_LENGTH_MILLISECONDS); } private void resumeGame(long milliseconds) { Log.i(TAG, "resumeGame"); // Create a new timer for the correct length and start it. gameIsInProgress = true; timerMilliseconds = milliseconds; createTimer(milliseconds); countDownTimer.start(); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。