2016-07-28 3 views
2

自分のアプリに報酬を与えたビデオ広告を、ビデオを追加する動画アクティビティに移動したときにクリックすると、ボタンが含まれているアクティビティが統合されましたが、問題は動画が表示に時間がかかることです進捗ダイアログとVideovisibiltyが "true"になると、進行状況ダイアログと自動クリックボタンが表示され、ビデオが表示されます。ビデオがアンドロイドで利用可能なときにボタンを自動クリックする方法は?

どうすればいいですか?

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

これが役に立ったら、それを親切に受け入れるようにしてください。そうすれば、他のユーザーもこの恩恵を受けることができます。 –

関連する問題