Last active
August 29, 2015 13:57
-
-
Save AvatarQing/9404240 to your computer and use it in GitHub Desktop.
StartApp广告Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<com.startapp.android.publish.banner.Banner | |
android:id="@+id/start_app_banner_ad" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | |
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> | |
<!-- These permissions are only required for showing the ad when pressing the Home button --> | |
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> | |
<uses-permission android:name="android.permission.GET_TASKS" /> | |
<activity | |
android:name="com.startapp.android.eula.EULAActivity" | |
android:configChanges="keyboard|keyboardHidden|orientation" | |
android:theme="@android:style/Theme.Translucent" > | |
</activity> | |
<activity | |
android:name="com.startapp.android.publish.list3d.List3DActivity" | |
android:taskAffinity="<package_name>.AppWall" | |
android:theme="@android:style/Theme" > | |
</activity> | |
<activity | |
android:name="com.startapp.android.publish.AppWallActivity" | |
android:configChanges="keyboardHidden|orientation" | |
android:taskAffinity="<package_name>.AppWall" | |
android:theme="@android:style/Theme" > | |
</activity> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity { | |
public static final String TAG = MainActivity.class.getSimpleName(); | |
private StartAppAd mStartAppAd = null; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
initStartAppSDK(); | |
setContentView(R.layout.activity_main); | |
StartAppAd.showSplash(this, savedInstanceState); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
mStartAppAd.onResume(); | |
} | |
@Override | |
protected void onPause() { | |
super.onPause(); | |
mStartAppAd.onPause(); | |
} | |
@Override | |
protected void onSaveInstanceState(Bundle outState) { | |
super.onSaveInstanceState(outState); | |
mStartAppAd.onSaveInstanceState(outState); | |
} | |
@Override | |
protected void onRestoreInstanceState(Bundle savedInstanceState) { | |
mStartAppAd.onRestoreInstanceState(savedInstanceState); | |
super.onRestoreInstanceState(savedInstanceState); | |
} | |
@Override | |
public void onBackPressed() { | |
mStartAppAd.onBackPressed(); | |
super.onBackPressed(); | |
} | |
private void initStartAppSDK() { | |
String developerId = getString(R.string.start_app_developer_id); | |
String appId = getString(R.string.start_app_app_id); | |
StartAppAd.init(this, developerId, appId); | |
StartAppSearch.init(this, developerId, appId); | |
mStartAppAd = new StartAppAd(this); | |
} | |
private void showStartAppSearchBox() { | |
StartAppSearch.showSearchBox(this); | |
} | |
private void showStartAppIntersititialAd() { | |
if (mStartAppAd.isReady()) { | |
mStartAppAd.showAd(); | |
mStartAppAd.loadAd(); | |
} else { | |
mStartAppAd.loadAd(new AdEventListener() { | |
@Override | |
public void onReceiveAd(Ad ad) { | |
Log.d(TAG, "onReceiveAd():" + ad.getClass().getSimpleName()); | |
if (mStartAppAd.isReady()) { | |
mStartAppAd.showAd(); | |
mStartAppAd.loadAd(); | |
} | |
} | |
@Override | |
public void onFailedToReceiveAd(Ad ad) { | |
Log.d(TAG, "onFailedToReceiveAd():" | |
+ ad.getClass().getSimpleName()); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment