1
我有一個廣告活動,但我想從string.xml獲取廣告單元ID,任何人都可以告訴我我該怎麼做?如何從字符串資源中獲取廣告單元ID和AddTest設備
我在strings.xml檔案此字符串資源:
<string name="KAM">"ca-app-pub-7024462642830025/8524979991"</string>
我想把這個這個活動
package com.JimSoft.Entertainment.Edu.LearnWithEnuma;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
public class LetraRActivity extends Activity implements OnInitListener{
/** The view to show the ad. */
private AdView adView;
//Si encuentras este codigo le pertenece a JimSoft Entertainment Ltda.
//ID AdMob
private static final String AD_UNIT_ID = "ca-app-pub-4561187343062246/6585366415";
private TextToSpeech TextToSpeechBienvenida;
private String TextoLetra;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_letra_r);
TextToSpeechBienvenida = new TextToSpeech(this, this);
TextoLetra = (String)getString(R.string.ConceptoLetraR);
// Se crea La Publicidad
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.Publicidad);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("37C65A6A5B1003E8")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
private void ParametrosHablar (String str)
{
TextToSpeechBienvenida.speak(str, TextToSpeech.QUEUE_FLUSH, null);
TextToSpeechBienvenida.setSpeechRate(-2.0f);
TextToSpeechBienvenida.setPitch(0.0f);
}
public void onInit(int status) {
//Se llama al metodo "cargarPreferencias"
ParametrosHablar(TextoLetra.toString());
if (status == TextToSpeech.LANG_MISSING_DATA | status == TextToSpeech.LANG_NOT_SUPPORTED)
{
Toast.makeText(this, "ERROR LANG_MISSING_DATA | LANG_NOT_SUPPORTED", Toast.LENGTH_SHORT).show();
}
}
public void IniciarAtras(View v){
Intent LanzarLetraQ = new Intent(this, LetraQActivity.class);
startActivity(LanzarLetraQ);
overridePendingTransition(R.anim.animacion_derecha_entrada, R.anim.animacion_derecha_salida);
finish();
}
public void IniciarAdelante(View v){
Intent LanzarLetraS = new Intent(this, LetraSActivity.class);
startActivity(LanzarLetraS);
overridePendingTransition(R.anim.animacion_izquierda_entrada, R.anim.animacion_izquierda_salida);
finish();
}
@Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
}
@Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
/** Llamada despues de que una actividad es destruida */
@Override
public void onDestroy() {
// Destroy the AdView.
if (adView != null) {
adView.destroy();
}
super.onDestroy();
if (TextToSpeechBienvenida != null)
{
TextToSpeechBienvenida.stop();
TextToSpeechBienvenida.shutdown();
}
super.onDestroy();
}
}
謝謝你,我可以爲同一件事DeviceTest? – 2014-09-26 16:14:16