我创建并发布了一个非常简单的Android应用程序,主要由WebView组成。我没有收到任何关于崩溃或错误的报告,除了我的一个朋友甚至无法启动应用程序。有问题的手机是运行Android 2.2.2版本的摩托罗拉Defy(MB525)。每当我的朋友尝试打开应用程序时,都会显示一条错误消息,指出进程已意外停止,请重试。
我已经在虚拟设备上运行该应用程序,摩托罗拉Droid运行Android版本2.3.7,这与我的朋友的手机尽可能接近,但由于应用程序运行顺利,我无法重现问题。在Motorola Defy或Android 2.2.2版上使用WebView的应用程序是否存在任何已知问题?或者有人可以给我任何关于如何解决这个问题的提示吗?
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 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>`
答案 0 :(得分:0)
由于在Android 2.2上缺乏对Google Play服务的支持,因此无效。立即行动!