I'm trying to port a Flash based game to Android.
I've ported it successfully (WebView), but now, the problem is that when I do a short click (short tap) somewhere in the game, it does 2 clicks (double tap), and when I do a long click (long tap) it does a short click (short tap).This is really annoying, specially when it does double fire instead of one fire. I've tried with the touch screen and a mouse; both had the same issue, so the input isn't the problem.
After reading a lot of stuff I think it must be a bug(?) on Andriod (4.x+ I think) WebView.
I hope you can help me to invert those things or to prevent those double taps as soon as possible.
Here is the code of the MainActivity.java:
package usr.sh.raul.dofus;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
#SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity
{
WebView mWebView;
/** Called when the activity is first created. */
#SuppressLint("SdCardPath")
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.setBackgroundColor(Color.parseColor("#000000"));
mWebView.loadUrl("file:///sdcard/Android/data/usr.sh.raul.dofus/data/loader.swf");
}
}
Thank you in advance and sorry for my bad english.
Related
I am loading a webView in my app that displays some buttons, each button starts a route that is generated using google maps.
The problem is that when I click "Navigate in app" nothing happens.
I was having the URL_UNKOWN_SCHEME error but solved it by adding and #override
My code looks like this:
package com.example.listarehtgps2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
WebView web;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = findViewById(R.id.webview);
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
web.loadUrl("webViewURL replaced for privacy reasons");
web.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// When user clicks a hyperlink, load in the existing WebView
if(url.contains("intent:")) {
Uri gmmIntentUri = Uri.parse(url);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
startActivity(mapIntent);
return true;
}
view.loadUrl(url);
return true;
}
}
);
}
}
I can not find any solution to open the link in the google maps app.
I managed to solve the UNKWN_URL_SCHEME but this is frustrating now.
Thanks in advance!
The URL_UNKOWN_SCHEME is because it's not recognising the scheme part of your URI (the bit up to :), are your URIs simply starting with "intent:" ?
To open a map at a location, try switching to the geo scheme, so a URI something like "geo:0.01,0.01?q=London" (along ofc with changing your url.contains check to look for that). You could also insert a mapIntent.setPackage("com.google.android.apps.maps") before the call to startActivity(mapIntent) if you want Google maps to take priority over any other map application the user may have installed.
If however you want navigation, use a URI starting with google.navigation such as "google.navigation:London" or "google.navigation:0.01,0.01", equally for street view you can use a URI starting with google.streetview
I'm working on a simple number guessing game. At the moment I have it set that when you guess the correct number it takes you to WinActivity.java. All I want it to do on that screen is say "You won" and to play a little trumpet victory sound (and also display a button that'll bring them to the GameActivity if they want to play again).
The trouble is, when I try bringing in a MediaPlayer the app doesn't even start.
Here is my code for my WinActivity that contains the MediaPlayer.
package com.example.jeremy.numberguessinggame;
import android.content.Intent;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class WinActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_win);
MediaPlayer trumpetsound = MediaPlayer.create(this,R.raw.trumpet);
trumpetsound.start();
Button btnPlayAgain = (Button) findViewById(R.id.button2);
TextView youWon = (TextView) findViewById(R.id.textViewYouWon);
btnPlayAgain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent playAgainIntent = new Intent(WinActivity.this,GameActivity.class);
startActivity(playAgainIntent);
}
});
}
}
When I run the app the Messages Gradle Build window will pop up and says "error: cannot find symbol variable raw".
I added the raw folder to the res location, and was able to drag the sounds into the folder no problem.
I just don't see why I can't make this MediaPlayer work.
I would love some help. If you need more information I'll be glad to give it to you.
I am trying to code an action bar for my android app and i defined my object to set the logo of the action bar to the default andorid icon before i update. When i run just that code, i get an error on the marked line.
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
public class myabDemo extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_myab_demo);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.drawable.ic_launcher); // ***Error appears here***
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
}
}
It's not R.drawable.icon_launcher but R.drawable.ic_launcher (At least i'm pretty sure you followed the tutorial that puts ic_launcher and not icon_launcher)
I guess you received a nullpointer exception, since actionBar is null.
Add the code below:
requestWindowFeature(Window.FEATURE_NO_TITLE);
So I'm fairly new to Java coding and I'm trying to create a simple code to have an edit text value act as a url for an intent internet command. I'm using this in Eclipse and ADT. The following is my java code.
import android.widget.EditText;
import android.widget.Button;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View.OnClickListener;
import android.view.View;
import android.content.Intent;
import android.net.Uri;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
EditText UR_L=(EditText) findViewById(R.id.ur_l);
String sUR_L= new String(UR_L.getText().toString());
Intent brwsrintnt = new Intent(Intent.ACTION_VIEW, Uri.parse(sUR_L));
startActivity(brwsrintnt);
}
});
In my layout I have a 2 buttons and an edit box but the edit box reflects a missing input type error. I have no idea how to fix this and I've looked many places.
Thanks,
David
I think your problem might be that the EditText is never intialized until you have already hit the button, so when you go to get text from it, it doesn't know the user has already entered something. Try moving
EditText UR_L=(EditText) findViewById(R.id.ur_l);
to just before you set the OnClickListener and see if anything changes
I would like to add a share button in an action bar of my current activity.
I don't know how to do it.
Is it possible to do this in activity ?
Here is the code of my activity :
package com.rss.utils;
import com.rss.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class WebBrowserViewActivity extends Activity {
WebView webview;
ProgressBar progressB = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_browser_view);
Intent intent = getIntent();
String url = intent.getStringExtra("URL");
Log.d("WebBrowserViewActivity", "URL to load : " +url);
progressB = (ProgressBar) findViewById(R.id.progressBar1);
webview = (WebView) findViewById(R.id.webViewArticle);
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
// webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setSupportZoom(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
if(progress < 100 && progressB.getVisibility() == ProgressBar.GONE){
progressB.setVisibility(ProgressBar.VISIBLE);
}
progressB.setProgress(progress);
if(progress == 100) {
progressB.setVisibility(ProgressBar.GONE);
}
}
});
webview.loadUrl(url);
}
}
Thanks a lot for your help.
++
I've never done that before but I did some research for you and I'm pretty sure this is what you're looking for.
This article will tell you what to do :)
In addition to what #Matthew said, this answer on question How to track the Share button clicked on the ActionBar? provides step wise details to do the same. Some of other links that may help are: How to activate "Share" button in android app? and Adding share action in ActionBar. Hope this helps.