Skip to content Skip to sidebar Skip to footer

Handling A Share Button Click On Android Game

Hi I want handle a click on Screen. The class does not extends an activity class so I cannot use any trivial method to handle the click. I know how to handle the click on android a

Solution 1:

In your Main activity class, define a share method:

publicvoid share(){
 runOnUiThread(new Runnable(){
            @Override
            publicvoid run() {
                 Intent iShare = new Intent(Intent.ACTION_SEND);
            iShare.setType("text/plain");
            iShare.putExtra(Intent.EXTRA_SUBJECT, "Download The Game");
            iShare.putExtra(Intent.EXTRA_TEXT, "Get The Game"+" "+"https://play.google.com/store/apps/details?id=com.jdtfans.jdtfootballkickers");
          try{
                startActivity(Intent.createChooser(iShare,"Share Via"));
            }catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getApplicationContext(),
                        "No Sharing Client Installed, Toast.LENGTH_SHORT)
                        .show();
            }
                }        
             });
    }

Then in your GameOverScene Class, Uncomment the line below and change "Share" to "shareAction":

CCMenuItemImageshareI= CCMenuItemImage.item("Image/MainMenu/share.png", "Image/MainMenu/Share.png", this, "shareAction");

Then, define the shareAction method below the restartAction() method:

publicvoidshareAction(Object sender) {
 if (BeetleshotMainActivity.app._soundplay == true)
            _soundMananger.ePlayButtonClickSound();  
         BeetleshotMainActivity.app.share();  
        }

Post a Comment for "Handling A Share Button Click On Android Game"