2016-07-28 71 views
2

我在我的應用程序集成了一些獎勵的視頻廣告包含一個名爲Show Video按鈕的活動當我點擊我瀏覽到視頻活性,其顯示的視頻增加了,但問題是,視頻需要時間來觀看,我想展示一個進度對話框,當Videovisibilty變爲「真」,然後隱藏進度對話框和自動點擊按鈕顯示視頻。如何在android中有視頻時自動點擊按鈕?

我該怎麼做?

mainActivity代碼: -

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     _button = (Button) findViewById(R.id.show_button); 
     _button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Intent i = new Intent(MainActivity.this, Video.class); 
       startActivity(i); 
      } 
     }); 


    } 

視頻活動代碼: -

String TAG = MainActivity.class.getSimpleName(); 
    private Supersonic mMediationAgent; 
    private Placement mPlacement; 
    ProgressDialog progress; 

    @Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     progress = new ProgressDialog(this); 
     progress.setMessage("Loading video :) "); 
     progress.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
     progress.setIndeterminate(true); 
     progress.show(); 

     mMediationAgent = SupersonicFactory.getInstance(); 
     // Supersonic Advertiser SDK call 
     SupersonicAdsAdvertiserAgent.getInstance().reportAppStarted(Video.this); 
     mMediationAgent.setRewardedVideoListener(Video.this); 
     final String userId = "9555515291"; 
     final String appKey = "50427d"; 
     mMediationAgent.initRewardedVideo(Video.this, appKey, userId); 
     IntegrationHelper.validateIntegration(Video.this); 
     if (mMediationAgent.isRewardedVideoAvailable()) { 
      mMediationAgent.showRewardedVideo("DefaultRewardedVideo"); 
     } 


    } 

    @Override 
    public void onRewardedVideoInitSuccess() { 
     Log.d(TAG, "onRewardedVideoInitSuccess"); 
    } 

    @Override 
    public void onRewardedVideoInitFail(SupersonicError supersonicError) { 

    } 

    @Override 
    public void onRewardedVideoAdOpened() { 
     Log.d(TAG, "onRewardedVideoAdOpened"); 
    } 

    @Override 
    public void onRewardedVideoAdClosed() { 
     // called when the video is closed 
     Log.d(TAG, "onRewardedVideoAdClosed"); 

     // here we show a dialog to the user if he was rewarded 
     if (mPlacement != null) { 
      // if the user was rewarded 
      showRewardDialog(mPlacement); 
      mPlacement = null; 
     } 

    } 

    @Override 
    public void onVideoAvailabilityChanged(boolean b) { 
     // called when the video availbility has changed 
     Log.d(TAG, "onVideoAvailabilityChanged" + " " + b); 

    } 

    @Override 
    public void onVideoStart() { 
     // called when the video has started 
     Log.d(TAG, "onVideoStart"); 
    } 

    @Override 
    public void onVideoEnd() { 
     // called when the video has ended 
     Log.d(TAG, "onVideoEnd"); 
    } 

    @Override 
    public void onRewardedVideoAdRewarded(Placement placement) { 
     // called when the video has been rewarded and a reward can be given to the user 
     Log.d(TAG, "onRewardedVideoAdRewarded" + " " + placement); 
     mPlacement = placement; 
    } 

    @Override 
    public void onRewardedVideoShowFail(SupersonicError supersonicError) { 
     // called when the video has failed to show 
     // you can get the error data by accessing the supersonicError object 
     // supersonicError.getErrorCode(); 
     // supersonicError.getErrorMessage(); 
     Log.d(TAG, "onRewardedVideoShowFail" + " " + supersonicError); 
    } 

    public void showRewardDialog(Placement placement) { 
     AlertDialog.Builder builder = new AlertDialog.Builder(Video.this); 
     builder.setPositiveButton("ok", new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       dialog.dismiss(); 
      } 
     }); 
     builder.setTitle(getResources().getString(R.string.rewarded_dialog_header)); 
     builder.setMessage(getResources().getString(R.string.rewarded_dialog_message) + " " + placement.getRewardAmount() + " " + placement.getRewardName()); 
     builder.setCancelable(false); 
     AlertDialog dialog = builder.create(); 
     dialog.show(); 
    } 
} 
+0

如果我的回答可以幫助那麼笑納它,這樣其他用戶就可以得到這個好處。 –

回答

1

只需撥打performClick()

btnViewVideo.performClick(); 

當您在使用本在這一點上的任何行動寫onclick listner將被自動觸發。

欲瞭解更多信息: fire button's click event programmatically

+0

如果這有幫助,那麼請接受它,以便其他用戶可以從中受益。 –

相關問題