如何Flurry与Flurry集成在android中添加监听器

时间:2013-02-15 12:29:47

标签: android flurry

我想在我的应用中集成乱舞。在下面的代码中,我整合了乱舞,但在android中无法正常工作。乱舞的监听器调用它的方法两次。如何运作请帮助我。

LoginActivity.java

public class LoginActivity extends Activity implements OnClickListener,
        AsyncTaskCompleteListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        instance = this;
        setContentView(R.layout.login_activity);
        Map<String, String> map = new HashMap<String, String>();
                map.put("url", NFLConstanants.LOGIN_URL);
                map.put("username", strUser);
                map.put("passwd", strPassword);
                new ParseController(LoginActivity.this, map,
                        NFLConstanants.SERVICE_CODE0, 1);
    }
    @Override
    protected void onStart() {
            super.onStart();
            System.out.println("call on start method");
            FlurryAgent.onStartSession(this, MACUtils.APIKEY_FLURRY);
            FlurryAgent.enableTestAds(true);
            FlurryAgent.initializeAds(this);
            FlurryAgent.setLogEnabled(true);

    }

    @Override
    protected void onStop() {
            super.onStop();
            System.out.println("call on stop method");
            FlurryAgent.onEndSession(this);
    }

    @Override
    public void onTaskCompleted(String responce, int sc) {
            if (FlurryAgent.isAdAvailable(LoginActivity.this,
                                    MACUtils.myAdSpaceName,
                                    FlurryAdSize.FULLSCREEN, MACUtils.timeout)) {

                                final String msgv = "To help keep this app free please watch this short video. Thanks";
                                AlertDialog.Builder dlg = new AlertDialog.Builder(
                                        LoginActivity.this);
                                dlg.setCancelable(false);
                                dlg.setTitle("Message");
                                dlg.setMessage(msgv);
                                dlg.setPositiveButton("OK",
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(
                                                    DialogInterface dialog,
                                                    int which) {

                                                try {
                                                    MyAdListener myAdListener = new MyAdListener(
                                                            LoginActivity.this,
                                                            LoginActivity.this, "3");
                                                    FlurryAgent
                                                            .setAdListener(myAdListener);
                                                    FrameLayout container = new FrameLayout(
                                                            LoginActivity.this);
                                                    FlurryAgent
                                                            .getAd(LoginActivity.this,
                                                                    MACUtils.myAdSpaceName,
                                                                    container,
                                                                    FlurryAdSize.FULLSCREEN,
                                                                    MACUtils.timeout);

                                                } catch (Exception e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        });
                                AlertDialog alert = dlg.create();
                                alert.show();
                            } 
         }
}

MyAdListener.java

public class MyAdListener implements FlurryAdListener {
    public Activity activity;
    public Context ctx;
    String pagePosition;
    boolean isDialogLaunch = false;

    public MyAdListener(Activity act, Context ctx, String page) {
        this.activity = act;
        this.pagePosition = page;
        this.ctx = ctx;
        this.isDialogLaunch = false;
    }

    @Override
    public boolean shouldDisplayAd(String myAdSpaceName, FlurryAdType type) {
        System.out.println("shouldDisplayAd:: " + type);
        return true;
    }

    @Override
    public void onAdClosed(String myAdSpaceName) {
        System.out.println("onAdClosed::: " + myAdSpaceName);
        if (pagePosition.equals("1") || pagePosition.equals("2")) {
            actionOnFlurryVideo();
        } else {
            if (!FlurryAgent.isAdAvailable(activity, MACUtils.myAdSpaceName,
                    FlurryAdSize.FULLSCREEN, MACUtils.timeout)) {
                Intent macIntent = new Intent(activity, MACCustomTab.class);
                macIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                activity.startActivity(macIntent);
                activity.finish();
            }
        }
    }

    @Override
    public void onApplicationExit(String myAdSpaceName) {
        System.out.println("onApplicationExit:: " + myAdSpaceName);
        actionOnFlurryVideo();
    }

    @Override
    public void onRenderFailed(String adSpace) {
        System.out.println("onRenderFailed:: " + adSpace);
        actionOnFlurryVideo();
    }

    @Override
    public void spaceDidReceiveAd(String adSpace) {
        System.out.println("spaceDidReceiveAd:: " + adSpace);
    }

    @Override
    public void spaceDidFailToReceiveAd(String adSpace) {
        System.out.println("spaceDidFailToReceiveAd:: " + adSpace);
    }

    @Override
    public void onAdClicked(String id) {
        System.out.println("onAdClicked:: " + id);
    }

    @Override
    public void onAdOpened(String id) {
        System.out.println("onAdOpened::: " + id);
    }

    public void actionOnFlurryVideo() {
        System.out.println("call actionOnflurryvideo");
        if (pagePosition.equals("1") || pagePosition.equals("2")) {
            if (!isDialogLaunch) {
                isDialogLaunch = true;
                final String msg = "Thanks for supporting our free website. Your bet has now been confirmed.";
                AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
                dlg.setCancelable(false);
                dlg.setTitle("Message");
                dlg.setMessage(msg);
                dlg.setPositiveButton("OK",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                NavigationGroupActivity parent = ((NavigationGroupActivity) activity
                                        .getParent());
                                parent.backToFirst();
                            }
                        });
                AlertDialog alert = dlg.create();
                alert.show();
            }
        } else {
            Intent macIntent = new Intent(activity, MACCustomTab.class);
            macIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            activity.startActivity(macIntent);
            activity.finish();
        }
    }

}

1 个答案:

答案 0 :(得分:1)

此问题将在我们的下一个版本中修复,预计很快就会发布。

(完全披露:我在Flurry的支持团队工作)