gpt4 book ai didi

java - 如何在应用程序点击按钮设置上显示 Admob 插页式广告

转载 作者:太空宇宙 更新时间:2023-11-04 13:08:21 24 4
gpt4 key购买 nike

强文本根据 Google 的指南,不建议在应用加载或退出时展示广告。

如何在应用点击按钮设置上显示 Admob 插页式广告或仅播放一次?

ResultLoadListner, OnItemClickListener, OnTaskCompleted, OnClickListener {

    private ListView listView;
private ListAdapter adapter;
public static List<RingtoneDetails> ringtons;
private InterstitialAd interstitial;
private ImageView stop;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initialise the varialbes
this.initialiseVariables();

setContentView(R.layout.layout_home_activity);
listView = (ListView) this.findViewById(R.id.main_grid_view);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
stop = (ImageView) findViewById(R.id.stop);
stop.setOnClickListener(this);

/***/
/*-----------------admob code------------*/
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest request = new AdRequest.Builder().build();
adView.loadAd(request);
interstitial = new InterstitialAd(getBaseContext());
interstitial.setAdUnitId(getResources().getString(
R.string.interstitial_id));
interstitial.loadAd(request);

// startloading results
LoadRingtonThread thread = new LoadRingtonThread(HomeActivity.this);
thread.execute("");

}

public void initialiseVariables() {
ringtons = new ArrayList<RingtoneDetails>();
adapter = new ListAdapter(HomeActivity.this, ringtons);
// SOURCE_URL = this.getResources().getString(R.string.source_url);
}

@Override
public void onResultLoad(RingtoneDetails... details) {
for(RingtoneDetails detail:details){
ringtons.add(detail);
this.adapter.notifyDataSetChanged();
}

}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
RingtonePlayer player=new RingtonePlayer(ringtons.get(position).getRingtoneid(),HomeActivity.this);
player.startPlaying();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case (SettingDialog.CONTACT_CHOOSER_ACTIVITY_CODE):
if (resultCode == Activity.RESULT_OK) {

try {
Uri contactData = data.getData();
String contactId = contactData.getLastPathSegment();
String[] PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER, };
Cursor localCursor = getContentResolver().query(
contactData, PROJECTION, null, null, null);
localCursor.moveToFirst();


String contactID = localCursor.getString(localCursor
.getColumnIndexOrThrow("_id"));
String contactDisplayName = localCursor.getString(localCursor
.getColumnIndexOrThrow("display_name"));

Uri localUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI,
contactID);
localCursor.close();
ContentValues localContentValues = new ContentValues();

localContentValues.put(ContactsContract.Data.RAW_CONTACT_ID, contactId);
localContentValues.put(ContactsContract.Data.CUSTOM_RINGTONE,
SettingDialog.filePath);
getContentResolver().update(localUri, localContentValues,
null, null);

Toast.makeText(this,
"Ringtone assigned to: " + contactDisplayName,
Toast.LENGTH_LONG).show();

} catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}
break;
}
}
@Override
public void onBackPressed() {
if (interstitial.isLoaded()) {
interstitial.show();
}
super.onBackPressed();
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
RingtonePlayer.stopPlaying();
stop.setVisibility(ImageView.GONE);
}
@Override
public void onTaskCompleted() {
// TODO Auto-generated method stub
stop.setVisibility(ImageView.GONE);
}

@Override
public void onTaskStart() {
stop.setVisibility(ImageView.VISIBLE);
}
}

最佳答案

您从 onBackPressed 中删除此代码并将其添加到 onClick 处理程序中。

    @Override
protected void onCreate(Bundle savedInstanceState) {
...

final Button myButton = ..
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
}
}

关于java - 如何在应用程序点击按钮设置上显示 Admob 插页式广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34207216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com