Skip to content

how to add interface and enum in this code. #28

Description

@palashmandokhot

import com.apptracker.android.listener.AppModuleListener;
import com.apptracker.android.track.AppTracker;
// Leadbolt SDK imports

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if(savedInstanceState == null) {
        // Initialize Leadbolt SDK with your api key
        AppTracker.startSession(getApplicationContext(),"YOUR_APP_API_KEY",AppTracker.ENABLE_AUTO_CACHE);
    }
    // cache Leadbolt Ad without showing it
    AppTracker.loadModuleToCache(getApplicationContext(),"inapp");
}

public void gameOver() {
    // call this when you want to display the Leadbolt Interstitial
    if(AppTracker.isAdReady("inapp")) {
            AppTracker.loadModule(getApplicationContext(),"inapp");
    }
}

}
AppTracker.setAgeRange("18-25");
// Allowed values for Age range are: "13-17", "18-25", "26-35", "36-45", "46+"

AppTracker.setGender("Female");
// Allowed values for Gender are: "Male", "Female"
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import com.apptracker.android.listener.AppModuleListener;
import com.apptracker.android.track.AppTracker;
// Leadbolt SDK imports

public class MainActivity extends Activity {

private AppModuleListener leadboltListener = new AppModuleListener() {
	@Override
	public void onModuleLoaded(String location) {
		// Add code here to pause game and/or all media including audio
	}
	@Override
	public void onModuleFailed(String location, String error, boolean isCache) {}
	@Override
	public void onModuleClosed(String location) {
		// Add code here to resume game and/or all media including audio
	}
	@Override
	public void onModuleClicked(String location) {}
	@Override
	public void onModuleCached(String location) {
		// Add code if not auto-recaching for when loadModuleModuleToCache is successful
	}
	@Override
	public void onMediaFinished(boolean viewCompleted) {
		if(viewCompleted) {
			Log.i("AppTracker", "User finished watching rewarded video");
		} else {
			Log.i("AppTracker", "User skipped watching rewarded video");
		}
	}
};
   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if(savedInstanceState == null) {
        // Initialize Leadbolt SDK with your api key
        AppTracker.setModuleListener(leadboltListener);
		AppTracker.startSession(getApplicationContext(),"YOUR_APP_API_KEY",AppTracker.ENABLE_AUTO_CACHE);
    }
    // cache Leadbolt Video Ad without showing it
    AppTracker.loadModuleToCache(getApplicationContext(),"video");
}

public void gameOver() {
    // call this when you want to display the Leadbolt Video
    if(AppTracker.isAdReady("video")) {
            AppTracker.loadModule(getApplicationContext(),"video");
    }      
}

}

1
2
3
4
5
AppTracker.setAgeRange("18-25");
// Allowed values for Age range are: "13-17", "18-25", "26-35", "36-45", "46+"

AppTracker.setGender("Female");
// Allowed values for Gender are: "Male", "Female"
private AppModuleListener leadboltListener = new AppModuleListener() {
@OverRide
public void onModuleLoaded(String location) {
Log.i("AppTracker", "Ad loaded successfully - "+location);
// Add code here to pause game and/or all media including audio
}
@OverRide
public void onModuleFailed(String location, String error, boolean isCache) {
if(isCache) {
Log.i("AppTracker", "Ad failed to cache - "+location);
} else {
Log.i("AppTracker", "Ad failed to display - "+location);
}
}
@OverRide
public void onModuleClosed(String location) {
Log.i("AppTracker", "Ad closed by user - "+location);
// Add code here to resume game and/or all media including audio
}
@OverRide
public void onModuleClicked(String location) {
Log.i("AppTracker", "Ad clicked by user - "+location);
}
@OverRide
public void onModuleCached(String location) {
Log.i("AppTracker", "Ad cached successfully - "+location);
// Add code if not auto-recaching for when loadModuleModuleToCache is successful
}
@OverRide
public void onMediaFinished(boolean viewCompleted) {
if(viewCompleted) {
Log.i("AppTracker", "User finished watching rewarded video");
} else {
Log.i("AppTracker", "User skipped watching rewarded video");
}
}
};

2
AppTracker.setModuleListener(leadboltListener);
AppTracker.startSession(getApplicationContext(),"YOUR_APP_API_KEY",AppTracker.ENABLE_AUTO_CACHE);

Activity

  1. ASHUTOSH2224 commented on Apr 2, 2024

    @ASHUTOSH2224

    import com.apptracker.android.listener.AppModuleListener;
    import com.apptracker.android.track.AppTracker;

    // Interface for AdType
    public interface AdType {
    String getLocation();
    }

    // Enum for Ad Locations
    public enum AdLocation implements AdType {
    INTERSTITIAL("inapp"),
    VIDEO("video");

    private final String location;

    AdLocation(String location) {
    this.location = location;
    }

    @OverRide
    public String getLocation() {
    return location;
    }
    }

    // Leadbolt SDK integration
    public class MainActivity extends Activity {

    private final AppModuleListener leadboltListener = new AppModuleListener() {
    // Implement methods for handling ad events (as before)
    };

    @OverRide
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
      AppTracker.setModuleListener(leadboltListener);
      AppTracker.startSession(getApplicationContext(), "YOUR_APP_API_KEY", AppTracker.ENABLE_AUTO_CACHE);
    
      // Cache Leadbolt ad based on AdType
      cacheAd(AdLocation.INTERSTITIAL);
    }
    

    }

    public void gameOver() {
    if (AppTracker.isAdReady(getSelectedAd().getLocation())) {
    AppTracker.loadModule(getApplicationContext(), getSelectedAd().getLocation());
    }
    }

    private AdType getSelectedAd() {
    // Choose the appropriate AdType based on your logic (e.g., return AdLocation.VIDEO)
    return AdLocation.INTERSTITIAL;
    }

    private void cacheAd(AdType adType) {
    AppTracker.loadModuleToCache(getApplicationContext(), adType.getLocation());
    }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions