嗨,我是Android开发的新手。但我需要完成下一步行动的任务:
我几乎做到了,但我不确定我是否正在使用正确的方法,我还有下一个问题:
这里我是如何开始这一系列动作的(应用程序类):
public void showVeedi(View view) {
final Context context = this;
Intent intent = new Intent(context, AdVeediActivity.class);
intent.putExtra("GAME_ID", 3);
intent.putExtra("GAME_LEVEL", getLevel());
startActivity(intent);
}
此处是AdVeediActivity类的一部分,其中包含广告活动(我将其用于预卷和midroll):
private MoPubInterstitial mInterstitial;
private AQuery aq;
private String vimeoUrl = "http://www.veedi.com/mobile/android/server/Feed.php?id=";
private String orientation = "portrait";
private String mopubId = "";
private boolean isInitialized = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ad_veedi);
aq = new AQuery(this);
Bundle extras = getIntent().getExtras();
vimeoUrl += extras.getInt("GAME_ID");
final Context context = this;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
if (extras.getBoolean("IS_PLAYER_EXIST") != true) {
aq.ajax(vimeoUrl, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject json, AjaxStatus status) {
try {
orientation = json.getString("orientation");
mopubId = json.getJSONObject("adUnits").getString("landscape");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
mInterstitial = new MoPubInterstitial((Activity) context, mopubId);
mInterstitial.setInterstitialAdListener((MoPubInterstitial.InterstitialAdListener) context);
mInterstitial.load();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
} else {
mInterstitial = new MoPubInterstitial(AdVeediActivity.this, extras.getString("MOPUB_ID"));
mInterstitial.setInterstitialAdListener((MoPubInterstitial.InterstitialAdListener) context);
mInterstitial.load();
}
}
@Override
protected void onDestroy(
) {
Bundle extras = getIntent().getExtras();
if (extras.getBoolean("IS_PLAYER_EXIST") != true) {
final Context context = this;
//------------ Here I call activity with webview with video inside
Intent intent = new Intent(context, MainVeediActivity.class);
intent.putExtra("GAME_LEVEL", extras.getInt("GAME_LEVEL"));
intent.putExtra("GAME_ID", extras.getInt("GAME_ID"));
intent.putExtra("MOPUB_ID", mopubId);
intent.putExtra("ORIENTATION", orientation);
startActivity(intent);
} else {
}
mInterstitial.destroy();
super.onDestroy();
}
@Override
public void onInterstitialLoaded(MoPubInterstitial moPubInterstitial) {
if (moPubInterstitial.isReady()) {
mInterstitial.show();
isInitialized = false;
} else {
// Other code
}
}
这里有视频课程(webview)MainVeediActivity,当用户clcick按钮进入时,也将上一课作为midrool运行
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_veedi);
Bundle extras = getIntent().getExtras();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
WebView.setWebContentsDebuggingEnabled(true);
webView = (WebView) findViewById(R.id.activity_main_veedi);
webView.getSettings().setAppCacheMaxSize(1);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.getSettings().setAppCacheEnabled(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavaScriptInterface(), "jsinterface");
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://www.veedi.com/mobile/player/" + extras.getInt("GAME_ID") + "/" + (extras.getInt("GAME_LEVEL") - 1) + ".html");
}
final Context context = this;
final class JavaScriptInterface {
JavaScriptInterface () { }
@JavascriptInterface
public void showMidroll() {
Bundle extras = getIntent().getExtras();
Intent intent = new Intent(context, AdVeediActivity.class);
intent.putExtra("IS_PLAYER_EXIST", true);
intent.putExtra("MOPUB_ID", extras.getString("MOPUB_ID"));
startActivity(intent);
}
@JavascriptInterface
public void closePlayer() {
((MainVeediActivity)context).finish();
}
}
您可以帮我解决问题,也可以采取措施解决问题。感谢。