I am trying to create a WebView app capable of behaving like the Facebook Messenger chat bubble that can overlay above other apps using the following github project:
https://github.com/siddharth2010/Bubbles
I downloaded the project and launched it, it works just fine with default parameters, but when clicking the "bubble" I want it to display a website instead of the placeholder image and text it currently has.
Here are the modifications I made:
sample_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView android:id="@+id/webView"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</RelativeLayout>
MainActivity.java
package com.irunawiki.irunawiki;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.irunawiki.bubbles.FloatingBubblePermissions;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView view = (WebView) findViewById(R.id.webView);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().getDomStorageEnabled();
view.setWebViewClient(new WebViewClient());
view.loadUrl("https://google.com");
FloatingBubblePermissions.startPermissionRequest(this);
View startBubble = findViewById(R.id.start_bubble);
startBubble.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startService(new Intent(getApplicationContext(), SimpleService.class));
}
});
}
}
AndroidManifest.xml
added these:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Attempting to run this in either the VM or an actual device will result in an immediate crash.
Curiously, it launches just find when only
WebView view = (WebView) findViewById(R.id.webView);
is uncommented, but any of the getSettings, setWebViewClient, loadUrl will cause the app to crash instantly on launch.
What exactly is causing the crash? I’m fairly new to Android Development but after hours of looking up stackoverflow posts with similar issues I have not been able to get it working…
2
Answers
As it turns out, I was trying to select a webview in a layout that wasn't active which caused the crash, the fix was to simply select the layout with the webview in it
I think you don’t have start_bubble view in your activity_main layout.
You should add button to your activity_main and after that u should change this line to this.
View startBubble = findViewById(R.id.start_bubble);
Button startBubble = findViewById(R.id.start_bubble);