Android创建预卷活动

时间:2014-12-09 14:23:20

标签: java android android-activity android-webview

嗨,我是Android开发的新手。但我需要完成下一步行动的任务:

    1. 在应用程序中单击“显示视频”按钮
    1. 从mopub中展示广告(预卷)
    1. 使用视频显示网页视图
    1. 在视频中点击按钮并显示midroll(来自mopub的广告)

我几乎做到了,但我不确定我是否正在使用正确的方法,我还有下一个问题:

  • 如果打开了视频(webview)活动,我崩溃了应用程序,之后我将其展开,它关闭了视频活动 (webview)并返回开始申请活动。
  • 当我从视频(webiew)活动打开midroll时,该活动是从应用程序的启动活动打开的,并关闭此midroll 之后,它也关闭和视频活动并返回我的应用程序 开始活动(但我需要保持视频活动(这是中间的) 应用程序启动活动和midroll之后的活动 预卷关闭)。

这里我是如何开始这一系列动作的(应用程序类):

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();
    }
}

您可以帮我解决问题,也可以采取措施解决问题。感谢。

0 个答案:

没有答案