I am totally new to Java but tried to make a really simple app which displays a website inside a GeckoView.
I could archive to load a website inside a GeckoView but once I try to change some Settings (UserAgentMode to DESKTOP) the app crashed once I try to open it on the phone (no errors shown). As I said I am totally new to Java - so it might be a beginner mistake - anyhow I can't figure it out on my own.
Here is the documentation for UserAgentMode: https://mozilla.github.io/geckoview/javadoc/mozilla-central/org/mozilla/geckoview/GeckoSessionSettings.html#USER_AGENT_MODE_DESKTOP
Where I am at the moment:
package com.example.geckotest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import org.mozilla.geckoview.GeckoRuntime;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.geckoview.GeckoView;
public class MainActivity extends AppCompatActivity {
private GeckoView geckoview;
private GeckoSession GeckoSession;
private GeckoRuntime geckoRuntime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GeckoView view = findViewById(R.id.geckoview);
GeckoSession session = new GeckoSession();
GeckoSession.getSettings().setInt(GeckoSessionSettings.USER_AGENT_MODE, 1);
GeckoRuntime runtime = GeckoRuntime.create(this);
session.open(runtime);
view.setSession(session);
session.loadUri("https://google.com");
}
}
This line causes the problem; when I comment them out, the app starts just fine - but not in the desired desktop mode:
GeckoSession.getSettings().setInt(GeckoSessionSettings.USER_AGENT_MODE, 1);