I have created and published a very simple Android app mainly consisting of a WebView. I haven't recieved any reports at all about crashes or bugs except from a friend of mine who can't even start the app. The phone in question is a Motorola Defy (MB525) running Android version 2.2.2. Every time my friend tries to open the app, an error message is displayed saying that the process has stopped unexpectedly, try again.

I have run the app on a virtual device, Motorola Droid running Android version 2.3.7, which was as close to my friend's phone as I could get but I didn't manage to reproduce the problem since the app ran smoothly. Are there any known issues with apps using WebView on Motorola Defy or Android version 2.2.2? Or can someone please give me any tips on how to get to the bottom of this problem?

MainActivity.java

package se.sebastianliljegren.inoff.info;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends Activity {

//***Not used***
@SuppressWarnings("unused")
private boolean services() {
    int isAvailable = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);
    if (isAvailable == ConnectionResult.SUCCESS) {
        return true;
    } else {
        Toast.makeText(this, "Google Play Services ej tillgänglig", Toast.LENGTH_SHORT)
                .show();
    }
    return false;
}

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


    //***AdMob Banner***
    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);



    //***WebView start***
    WebView myWebView = (WebView) findViewById(R.id.webView1);

    myWebView.setWebViewClient(new WebViewClient());
    WebSettings webSettings = myWebView.getSettings();
    //Zoombuttons
    myWebView.getSettings().setBuiltInZoomControls(true);
    myWebView.getSettings().setUseWideViewPort(true);

    webSettings.setSupportZoom(true);
    webSettings.setJavaScriptEnabled(true);
    myWebView.loadUrl("http://www.sebastianliljegren.se/inoff/android/lista.php");
    //***Webview end***
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    WebView myWebView = (WebView) findViewById(R.id.webView1);
    // Check if the key event was the Back button and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
        myWebView.goBack();
        return true;
    }
    // If it wasn't the Back key or there's no web page history, bubble up to the default
    // system behavior (probably exit the activity)
    return super.onKeyDown(keyCode, event);
}

}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="#cccccc">
 <WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="360dp"
android:layout_above="@+id/adView"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</WebView>
 <com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="*******************************" >
 </com.google.android.gms.ads.AdView>
</RelativeLayout>

Manifest

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="se.sebastianliljegren.inoff.info"
android:versionCode="3"
android:versionName="1.2" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />
<application
    android:allowBackup="true"
    android:icon="@drawable/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" />
      <meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS" />
    <activity
        android:name="se.sebastianliljegren.inoff.info.MainActivity"
        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="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
</manifest>`
有帮助吗?

解决方案

Didn't work due to the lack of support for Google Play Services on Android 2.2. Works now!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top