Reputation: 47
Okay, a very weird one for y'all. I have a VERY simple android application that contains two webview activities. They both (obviously) view a html webpage hosted on my server. Here's the problem; the app runs perfectly fine on my 6.0.1 device, but when I run it on my 5.1.1 TV box, it starts up like normal, the text input fields show the flashing indicator so I know its up and running. The indicator will flash 3 or 4 times then the app force closes.
Manifest.xml
package="myapp">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
<uses-feature android:name="android.hardware.screen.landscape" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.type.television" android:required="false" />
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature android:name="android.software.leanback" android:required="false"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault"
android:banner="@drawable/splash">
<activity
android:name="myapp.ShowWebView"
android:finishOnTaskLaunch="true"
android:label="@string/chat_name"
android:theme="@android:style/Theme.DeviceDefault"
android:excludeFromRecents="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="myapp.ShowWebViewTerms"
android:finishOnTaskLaunch="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:excludeFromRecents="false" />
</application>
And the activity that keeps failing:
public class ShowWebView extends Activity {
private boolean haveNetworkConnection() {
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo) {
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
//private Button button;
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//This will not show title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.show_web_view);
//Get webview
webView = (WebView) findViewById(R.id.webView1);
if(haveNetworkConnection()){
startWebView("http://mywebsite/chat/index.php");
} else {
webView.loadUrl("error.html");
}
}
private void startWebView(String url) {
//Create new webview Client to show progress dialog
//When opening a url or click on link
webView.setWebViewClient(new WebViewClient() {
//If you will not use this method url links are opeen in new brower not in webview
public boolean Override(WebView view, String url) {
view.loadUrl(url);
return true;
}
//If url has "tel:245678" , on clicking the number it will directly call to inbuilt calling feature of phone
public boolean shouldOverrideUrlLoading(WebView view ,String url){
if(url.startsWith("tel:")){
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(intent);
} else {
view.loadUrl(url);
}
return true; }
//Show loader on url load
});
// Javascript enabled on webview
webView.getSettings().setJavaScriptEnabled(true);
// Other webview options
/*
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.getSettings().setBuiltInZoomControls(true);
//Additional Webview Properties
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setLayoutAlgorithm(webView.getSettings().getLayoutAlgorithm().NORMAL);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(false);
webView.setSoundEffectsEnabled(true);
webView.setHorizontalFadingEdgeEnabled(false);
webView.setKeepScreenOn(true);
webView.setScrollbarFadingEnabled(true);
webView.setVerticalFadingEdgeEnabled(false);
*/
/*
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);
*/
//Load url in webview
webView.loadUrl(url);
}
// Open previous opened link from history on webview when back button pressed
@Override
// Detect when the back button is pressed
public void onBackPressed() {
if(webView.canGoBack()) {
finish();
} else {
// Let the system handle the back button
super.onBackPressed();
}
}
}
Unfortunately, because I am running into this error on a TV box, I have no way to debug for the actual issue. This is probably a long shot but I am new to android development and maybe I miss something you won't. Any help or tips are greatly appreciated. Thanks in advance!
Upvotes: 1
Views: 768
Reputation: 47
After enabling WiFi ADB, I was able to find that the manifest was missing this
uses-permission android:name="android.permission.WAKE_LOCK"
Going to leave this here in case anyone runs into the same or a similar issue.
Upvotes: 1