【问题标题】:how to add Interstitial?如何添加插页式广告?
【发布时间】:2014-08-11 20:27:59
【问题描述】:

这是我的活动,我将添加一个插页式广告。 如果此活动的 onPause 超过 30 秒,我会这样做,在 onResume 我想显示肠。 因为通过这个活动和另一个活动,这个应用程序必须打开 url,然后一旦你回到活动(超过 30 秒)我想添加一个插页式广告。 会是这样吗?如果是,怎么做?

活动

public class EpisodiActivity extends Activity {

AdView adView;

public class ViewModel {
    private String url;
    private String name;

    public ViewModel(String url, String name) {
        this.url = url;
        this.name = name;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return this.name;
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //creazione fullscreen activity
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.episodi_activity);

 // Look up the AdView as a resource and load a request.
    AdView adView = (AdView) this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

    String[] episodi = getIntent().getStringArrayExtra("Product");
    String[] urls = getIntent().getStringArrayExtra("urls");


    ListView mylist = (ListView) findViewById(R.id.listView1);

    // And in this loop we create the ViewModel instances from 
    // the name and url and add them all to a List
    List<ViewModel> models = new ArrayList<ViewModel>();
    for (int i = 0; i < episodi.length; i++) {
        String name = episodi[i];
        String url = "No value";//ok, so bye :Dwait 1 second please you now another code for this
        if (i < urls.length) {
            url = urls[i];
        }
        ViewModel model = new ViewModel(url, name);//, url);
        models.add(model);
    }


    // Here we create the ArrayAdapter and assign it to the ListView
    // We pass the List of ViewModel instances into the ArrayAdapter
    final ArrayAdapter<ViewModel> adapter = new ArrayAdapter<ViewModel>(this, android.R.layout.simple_list_item_1, models);

    mylist.setAdapter(adapter);


    mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {

            // Here we get the ViewModel at the given position
            ViewModel model = (ViewModel) arg0.getItemAtPosition(position);

            // And the url from the ViewModel
            String url = model.getUrl();

            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        }
    });
}

}

【问题讨论】:

    标签: android google-play-services banner interstitial


    【解决方案1】:

    将当前时间保存到 onPause 中的共享首选项 int。在 onResume 中将当前时间与保存的时间进行比较,如果超过 30 秒,您的插页式布局就会膨胀。

    可能看起来像这样:

    onPause():

    super.onPause();
    
    int pauseTime = System.currentTimeMillis();
    
    SharedPreferences sharedPrefs = getSharedPreferences(PREFS, 0);
    SharedPreferences.Editor editor = sharedPrefs.edit();
    editor.putInt("pauseTime", pauseTime);
    editor.commit();
    

    onResume:

    super.onResume();
    
    int currentTime = System.currentTimeMillis();
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    int pauseTime = sharedPrefs.getInt("pauseTime",0);
    
    int timePassed = currentTime - pauseTime;
    
    if(timePassed >= 30000) {
        // Launch your interstitial activity or call a function in this Activity that brings up your interstitial
    }
    

    【讨论】:

    • 你能告诉我一些代码行吗?添加插页式广告 我使用了新课程?
    • 您的插页式广告是否已有布局和活动?
    • 是的,活动是我上面写的,我必须在 XML 中添加一些东西?
    • 如果我正确理解了上面的活动,您将显示一个剧集列表,当用户选择一个剧集时,您就会触发开始该剧集的意图。正确的?因此,如果用户在此 Activity 中并且他们进入 onPause 并在 >= 30 秒后恢复,那么您将启动一个意图来调出插页式广告(很可能是广告,对吗?)。您已经知道如何启动意图,因为当有人点击剧集时您正在这样做。只需在时间检查后在 onResume 中执行此操作即可。
    • 当用户返回此活动时,我想在用户观看一集超过 30 秒的情况下投放广告
    猜你喜欢
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多