插页式广告; Google Play服务丢失了吗?

时间:2015-05-13 02:34:46

标签: java android ads interstitial

我只是完全屠宰如何广告插页式广告并需要帮助。当我使用示例插页式程序时,我的模拟器工作,但它不适用于我正在处理的当前应用程序。请帮助,我在这一点上绝望! 请不要介意过多的代码。

Java文件(许多额外代码):

 public class Settings extends ActionBarActivity {

private InterstitialAd mInterstitialAd;

public static final String MY_PREFS_NAME = "MyPrefsFile";

EditText calorieSet;



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

    // Create the InterstitialAd and set the adUnitId.
    mInterstitialAd = new InterstitialAd(this);
    // Defined in res/values/strings.xml
    mInterstitialAd.setAdUnitId(getString(R.string.ad_unit_id));

    //AdRequest adRequest = new AdRequest.Builder().build();
    //mInterstitialAd.loadAd(adRequest);

    calorieSet = (EditText) findViewById(R.id.calorieSet);

    SharedPreferences sharedPreferences =   getApplication().getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
    String calValue = sharedPreferences.getString("calValue", null);
    calorieSet.setText( calValue );


}




public void onClick(View view) {





    Intent i = new Intent(this, MainActivity.class);

    final EditText calorieSet = (EditText) findViewById(R.id.calorieSet);
    String userCals= calorieSet.getText().toString();
    i.putExtra("calorieSet", userCals);


    if (userCals == null || userCals.equals("")) {
        Toast.makeText(this, "Please enter a calorie number",  Toast.LENGTH_SHORT).show();
        return;
    } else { showInterstitial();
               // startActivity();
     }



         SharedPreferences sharedPreferences =   getApplication().getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("calValue", calorieSet.getText().toString());
    editor.commit();

    startActivity(i);}



    private void showInterstitial() {
    // Show the ad if it's ready. Otherwise toast and restart the game.
    if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
        mInterstitialAd.show();
    } else {
        Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show();
        startActivity();
    }
    }

    private void startActivity() {
    // Hide the retry button, load the ad, and start the timer.
    //mRetryButton.setVisibility(View.INVISIBLE);
    AdRequest adRequest = new AdRequest.Builder().build();
    mInterstitialAd.loadAd(adRequest);

    //mCountDownTimer.start();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_settings, menu);
    return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
    }
    }

的gradle:

    apply plugin: 'com.android.application'

     android {
     compileSdkVersion 22
     buildToolsVersion "22.0.0"

    defaultConfig {
    applicationId "com.pjproductions.thinr"
    minSdkVersion 9
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
     }
     buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),   proguard-rules.pro'
        }
     }
     }

     dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.android.support:appcompat-v7:22.0.0'
     compile 'com.google.android.gms:play-services:7.0.0'

清单

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pjproductions.thinr" >


<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data android:name="com.google.android.gms.version"    android:value="@integer/google_play_services_version"/>

    <activity
        android:name=".Settings"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />




            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
    </activity>


    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />


</application>

logcat错误:

        12 22:09:11.346  15622-15622/com.pjproductions.thinr W/GooglePlayServicesUtil﹕ Google Play services is missing.
        05-12 22:09:11.368  15622-15622/com.pjproductions.thinr I/WebViewFactory﹕ Loading com.android.webview version 39 (1737576-x86) (code 300007)
         05-12 22:09:11.378  15622-15622/com.pjproductions.thinr I/LibraryLoader﹕ Time to load native libraries: 1 ms (timestamps 6461-6462)
        05-12 22:09:11.378  15622-15622/com.pjproductions.thinr I/LibraryLoader﹕ Expected native library version number "",actual version number ""

0 个答案:

没有答案