How to close web-view automatically when URL changed in Android Flutter? - java

I want to close Web-View Automatically when URL is Changed. Here is the code i'm used to open a web-view in Flutter Android Application.
GestureDetector(
child: WebviewScaffold(
url: webUrl,
withJavascript: true,
withLocalStorage: true,
persistentFooterButtons: <Widget>[
RaisedBtn(
onPressed: (){
Screen();
flutterWebviewPlugin.dispose();
},
text: "Confirm",
)
],
),
),

please check example below. Flutter webview has single instance which you can retrieve as FlutterWebviewPlugin()
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
final _loginWebView = FlutterWebviewPlugin();
_onUrlChanged = _loginWebView.onUrlChanged.listen((String url) {
//check is it right url for navigation and navigate back or do nothing
});
Important!
Do not forget to dispose it.

Related

Ionic Capacitor Admob plugin loadAd null object reference

I am developing an Ionic Capacitor app and i am using the capacitor community ad plugin, but i am getting the following error in Android Studio:
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference
I am running the application on an android phone with the command ionic capacitor run android -l --external
This is how the error happens:
the app opens on the Welcome page
the app shows a banner ad
i click the login button
the app removes the banner ad
the app navigates to the login page
the app should show a banner ad, BUT the app crashes
Welcome page (login page has the same life cycle methods and calls):
ionViewWillLeave(): void {
this.removeAd();
}
ionViewWillEnter(): void {
this.showAd();
}
private async showAd(): Promise<void> {
await this.admobService.showBanner();
}
private async removeAd(): Promise<void> {
await this.admobService.removeBanner();
}
Admob service:
public async showBanner(): Promise<void> {
AdMob.addListener(BannerAdPluginEvents.FailedToLoad, (info) => {
//console.log(info);
});
const options: BannerAdOptions = {
adId: 'hidden',
adSize: BannerAdSize.BANNER,
position: BannerAdPosition.TOP_CENTER,
margin: 0,
isTesting: true,
};
AdMob.showBanner(options);
}
public async removeBanner(): Promise<void> {
await AdMob.removeBanner();
}
Admob service is provided in root, and maybe that could be the case? But i would not like to provide it in every page specifically
Probably, the banner destroys while it trying to show. You can try add a delay via setTimeout (a few seconds for check this idea) for this.showAd(); call:
ionViewWillEnter(): void {
setTimeout(() => { this.showAd(); }, 3000);
}

Apply Deep linking in flutter app for android and ios

Apply Deep Linking in flutter app to open
a specific page in another app or same app
i want to know to how implement deep links in flutter
or open channel with android native and ios native ?
?
I think it would be the same as in a normal android app. Deeplinking is a configuration thing rather than code.
You need to write some things in your android manifest.
Have a look at the firebase manual for deep linking:
Firebase deeplinking manual
You can use firebase dynamic links for deep linking in a flutter. Refer this link for full implement steps and create and receive a link, https://medium.com/better-programming/deep-linking-in-flutter-with-firebase-dynamic-links-8a4b1981e1eb.
Here is a sample code for receiving a link inside the app and open a new screen.
class MainWidgetState extends State<MainWidget> {
#override
void initState() {
super.initState();
this.initDynamicLinks();
}
initDynamicLinks(BuildContext context) async {
await Future.delayed(Duration(seconds: 3));
var data = await FirebaseDynamicLinks.instance.getInitialLink();
var deepLink = data?.link;
final queryParams = deepLink.queryParameters;
if (queryParams.length > 0) {
var userName = queryParams['userId'];
openNewScreen(userName);
}
FirebaseDynamicLinks.instance.onLink(onSuccess: (dynamicLink)
async {
var deepLink = dynamicLink?.link;
final queryParams = deepLink.queryParameters;
if (queryParams.length > 0) {
var userName = queryParams['userId'];
openNewScreen(userName);
}
debugPrint('DynamicLinks onLink $deepLink');
}, onError: (e) async {
debugPrint('DynamicLinks onError $e');
});
}
openNewScreen(String userName){
Navigator.of(context).pushNamed("routeFormScreen", arguments: {"name": userName});
}
}

How to add Google map for GWT into FormPanel

I am new to GWT and face some problem here. I need to show up Google map on a form in my GWT web.
First, there has a windowForm.class which extends FormPanel and I have wrote a mapWindowForm.class which extends this windowForm.class as below.
http://paste.ideaslabs.com/show/Q0ThysUrSF
And the problem is how shall I add this map "final MapWidget map = new MapWidget(Location, 2);" which is a MapWidget into this FormPanel: "mapWindowForm.class"
This system was developed by GWT-2.5.0. The library I have imported is gwt-maps-1.1.1.jar(Maps v2 API 1.1.1), so I give "2" as the second parameter in Maps.loadMapsApi(). Unfortunately, the first time to call mapWindowForm.class, the window.alert showed up, indicated that the Map.loadMapsApi() has not successed. But the second time to call this class, the window.alert didn't show up until I have refresh the web page. When I tried to give "3", it shows the sensor shall be given as true of false. When I tried to use gwt-maps-3.8.1(Maps v3 API), the import were not work.
I have tried some way to add this Map into frompanel as below
add(map);
LayoutContainer lc= new Layoutcontainer();
lc.add(map);
add(lc);
But both doesn't work, it just show a FormPanel with nothing on it.
I am not sure that is the MapWidget doesn't create or the MapWidget doesn't add into the FormPanel succeed
Thanks.
Hi Braj,
Thank you very much for your reply.
I have tried your suggestion in my code, but still face some problem.
mapWindowForm form = new mapWindowForm();
GoogleMap gmap = googleMap.create(form.getElement(), options);
But, I still don't how to add the gMap into my mapWindowForm.
Others form in this project would be code as below:(BaseWindow.java extends Window)
BaseWindow window = new BaseWindow(new mapWindowForm());
window.show();
And I have found this issue Example "Google Maps API v3 for GWT" Project for Eclipse.
As this issue claimed, I need to add <inherits name="com.google.maps.gwt.GoogleMaps" /> in my project.gwt.xml and a script to load map api. But some one also said cannot add script in gwt.xml.
So, I add inherits into gwt.xml and script into my project.html.
But I am bit of confuse, according to https://code.google.com/p/gwt-google-apis/wiki/MapsGettingStarted , it was import com.google.gwt.maps, but in this issue, it import com.google.maps.gwt, what's the different between them?
Thanks again.
I have tried below code(BaseWindow.java extends Window, windowForm.java extends FormPanel)
onClick(){
// MapOptions options = MapOptions.create() ;
// options.setCenter(LatLng.create( latCenter, lngCenter ));
// options.setZoom( 6 ) ;
// options.setMapTypeId( MapTypeId.ROADMAP );
// options.setDraggable(true);
// options.setMapTypeControl(true);
// options.setScaleControl(true) ;
// options.setScrollwheel(true) ;
windowForm panel = new mapWindowForm();
// GoogleMap gMap = GoogleMap.create( panel.getElement(), options ) ;
//BaseWindow(FormPanel formpanel, String ID, String title, int Height, int Weight)
BaseWindow window = new BaseWindow(panel,"Maps","This is Maps", 500, 650);
window.show();
}
This will show a form with title "This is Maps" and nothing in it.
But, when I unmark the toggle, the form will not be showed. Click the button will nothing happen. I am wonder is MapOptions doesn't work(API not load?) correct or some error because GWT container?
After created a new Google web application project and tried as below code:
public class Map implements EntryPoint {
public void onModuleLoad() {
FormPanel panel = new FormPanel();
panel.setWidth("100%");
panel.setHeight("100%");
MapOptions options = MapOptions.create();
options.setCenter(LatLng.create(23,-151));
options.setZoom(2);
options.setMapTypeId(MapTypeId.ROADMAP);
options.setDraggable(true);
options.setMapTypeControl(true);
options.setScaleControl(true);
options.setScrollwheel(true);
Button btn = new Button();
GoogleMap gMap = GoogleMap.create(panel.getElement(), options);
RootPanel.get().add(panel);
RootPanel.get().add(btn);
gMap.addIdleListener(new GoogleMap.IdleHandler() {
public void handle() {
Window.alert("Idle");
}
});
}
}
Also add gwt-map.3.8.1.jar into project and add configuration as below into Map.gwt.xml
<inherits name="com.google.maps.gwt.GoogleMaps" />
<script src="http://maps.google.com/maps/api/js?sensor=false" />
Compile success while with network connection.
But when run as web application, the url http://127.0.0.1:8888/Map.html?gwt.codesvr=127.0.0.1:9997 doesn't show up Google Map.
So, I have added a button, it has been showed. And add a idleListener, the Window.alert showed up, indicated that the map doesn't load.
On the other hand, in my project, add into gwt.xml still compile failed, because it doesn't support script tag, even with network connection. So, I have added script into home_page.html, but still failed to load the map. At the meantime, Window.alert also show up.
Connect to http://maps.google.com/maps/api/js?sensor=false in browser will get information as below
window.google = window.google || {};
google.maps = google.maps || {};
(function() {
function getScript(src) {
document.write('<' + 'script src="' + src + '"' +
' type="text/javascript"><' + '/script>');
}
var modules = google.maps.modules = {};
google.maps.__gjsload__ = function(name, text) {
modules[name] = text;
};
google.maps.Load = function(apiLoad) {
delete google.maps.Load;
apiLoad([0.009999999776482582,[[["http://mt0.googleapis.com/vt?lyrs=m#262000000\u0026src=api\u0026hl=zh-TW\u0026","http://mt1.googleapis.com/vt?lyrs=m#262000000\u0026src=api\u0026hl=zh-TW\u0026"],null,null,null,null,"m#262000000",["https://mts0.google.com/vt?lyrs=m#262000000\u0026src=api\u0026hl=zh-TW\u0026","https://mts1.google.com/vt?lyrs=m#262000000\u0026src=api\u0026hl=zh-TW\u0026"]],[["http://khm0.googleapis.com/kh?v=149\u0026hl=zh-TW\u0026","http://khm1.googleapis.com/kh?v=149\u0026hl=zh-TW\u0026"],null,null,null,1,"149",["https://khms0.google.com/kh?v=149\u0026hl=zh-TW\u0026","https://khms1.google.com/kh?v=149\u0026hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/vt?lyrs=h#262000000\u0026src=api\u0026hl=zh-TW\u0026","http://mt1.googleapis.com/vt?lyrs=h#262000000\u0026src=api\u0026hl=zh-TW\u0026"],null,null,null,null,"h#262000000",["https://mts0.google.com/vt?lyrs=h#262000000\u0026src=api\u0026hl=zh-TW\u0026","https://mts1.google.com/vt?lyrs=h#262000000\u0026src=api\u0026hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/vt?lyrs=t#132,r#262000000\u0026src=api\u0026hl=zh-TW\u0026","http://mt1.googleapis.com/vt?lyrs=t#132,r#262000000\u0026src=api\u0026hl=zh-TW\u0026"],null,null,null,null,"t#132,r#262000000",["https://mts0.google.com/vt?lyrs=t#132,r#262000000\u0026src=api\u0026hl=zh-TW\u0026","https://mts1.google.com/vt?lyrs=t#132,r#262000000\u0026src=api\u0026hl=zh-TW\u0026"]],null,null,[["http://cbk0.googleapis.com/cbk?","http://cbk1.googleapis.com/cbk?"]],[["http://khm0.googleapis.com/kh?v=84\u0026hl=zh-TW\u0026","http://khm1.googleapis.com/kh?v=84\u0026hl=zh-TW\u0026"],null,null,null,null,"84",["https://khms0.google.com/kh?v=84\u0026hl=zh-TW\u0026","https://khms1.google.com/kh?v=84\u0026hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/mapslt?hl=zh-TW\u0026","http://mt1.googleapis.com/mapslt?hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/mapslt/ft?hl=zh-TW\u0026","http://mt1.googleapis.com/mapslt/ft?hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/vt?hl=zh-TW\u0026","http://mt1.googleapis.com/vt?hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/mapslt/loom?hl=zh-TW\u0026","http://mt1.googleapis.com/mapslt/loom?hl=zh-TW\u0026"]],[["https://mts0.googleapis.com/mapslt?hl=zh-TW\u0026","https://mts1.googleapis.com/mapslt?hl=zh-TW\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=zh-TW\u0026","https://mts1.googleapis.com/mapslt/ft?hl=zh-TW\u0026"]],[["https://mts0.googleapis.com/mapslt/loom?hl=zh-TW\u0026","https://mts1.googleapis.com/mapslt/loom?hl=zh-TW\u0026"]]],["zh-TW","US",null,0,null,null,"http://maps.gstatic.com/mapfiles/","http://csi.gstatic.com","https://maps.googleapis.com","http://maps.googleapis.com"],["http://maps.gstatic.com/intl/zh_tw/mapfiles/api-3/16/11","3.16.11"],[662838505],1,null,null,null,null,0,"",null,null,0,"http://khm.googleapis.com/mz?v=149\u0026",null,"https://earthbuilder.googleapis.com","https://earthbuilder.googleapis.com",null,"http://mt.googleapis.com/vt/icon",[["http://mt0.googleapis.com/vt","http://mt1.googleapis.com/vt"],["https://mts0.googleapis.com/vt","https://mts1.googleapis.com/vt"],[null,[[0,"m",262000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],0],[null,[[0,"m",262000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],3],[null,[[0,"m",262000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],0],[null,[[0,"m",262000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],3],[null,[[4,"t",132],[0,"r",132000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],0],[null,[[4,"t",132],[0,"r",132000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],3],[null,null,[null,"zh-TW","US",null,18],0],[null,null,[null,"zh-TW","US",null,18],3],[null,null,[null,"zh-TW","US",null,18],6],[null,null,[null,"zh-TW","US",null,18],0],["https://mts0.google.com/vt","https://mts1.google.com/vt"],"/maps/vt"],2,500,["http://geo0.ggpht.com/cbk?cb_client=maps_sv.uv_api_demo","http://www.gstatic.com/landmark/tour","http://www.gstatic.com/landmark/config","/maps/preview/reveal?authuser=0","/maps/preview/log204","/gen204?tbm=map","http://static.panoramio.com.storage.googleapis.com/photos/"]], loadScriptTime);
};
var loadScriptTime = (new Date).getTime();
getScript("http://maps.gstatic.com/intl/zh_tw/mapfiles/api-3/16/11/main.js");
})();
How to add Google map for GWT into FormPanel?
Here is the code.
Simply call below line and the map is added in formPanel.
GoogleMap gMap = GoogleMap.create(formPanel.getElement(), options);
Some more configuration as defined below:
gwt.xml:
<inherits name="com.google.maps.gwt.GoogleMaps" />
<script src="http://maps.google.com/maps/api/js?sensor=false" />
gwt-maps.jar in build path of the project.
Sample code:
public void onModuleLoad() {
FormPanel formPanel = new FormPanel();
formPanel.setWidth("500px");
formPanel.setHeight("650px");
RootPanel.get().add(formPanel);
MapOptions options = MapOptions.create();
options.setZoom(6);
options.setMapTypeId(MapTypeId.ROADMAP);
options.setDraggable(true);
options.setMapTypeControl(true);
options.setScaleControl(true);
options.setScrollwheel(true);
GoogleMap gMap = GoogleMap.create(formPanel.getElement(), options);
gMap.setCenter(LatLng.create(58.378679, -2.197266));
}
screenshot:
I've been using the branflake API for quite some time, and currently it's working fine one GWT 2.8.
https://mvnrepository.com/artifact/com.github.branflake2267/gwt-maps-api
However, it's no longer maintained, some I'm shopping around for an alternative. In the meantime, I recommend it. The only downside being that it's using the 3.1 API version, which is obsolete. I'll post back if I find a way forward with it, or if I find an alternative.

How to restrict a user to login in only one tab/window using java and javascript?

My requirement is to give access like one login per user, For that I have updated the login Status to true in db when user login, and false when user logout.
But the problem is when user close the window without logout.
To handle window close I have implemented the following js code
var validNavigation = false;
function wireUpEvents() {
var dont_confirm_leave = 0;
var leave_message = 'You sure you want to leave?'
function goodbye(e) {
if (!validNavigation) {
if (dont_confirm_leave!==1) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = leave_message;
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
return leave_message;
}
window.location = "logout.jsp";
}
}
window.onbeforeunload=goodbye;
// Attach the event keypress to exclude the F5 refresh
$(document).bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});
// Attach the event click for all links in the page
$("a").bind("click", function() {
validNavigation = true;
});
// Attach the event submit for all forms in the page
$("form").bind("submit", function() {
validNavigation = true;
});
// Attach the event click for all inputs in the page
$("input[type=submit]").bind("click", function() {
validNavigation = true;
});
// Attach the event click for all inputs in the page
$("input[type='button']").bind("click", function() {
validNavigation = true;
});
}
// Wire up the events as soon as the DOM tree is ready
$(document).ready(function() {
wireUpEvents();
});
Here it works for window close, means if user close the window it goes to logout page, but problem is it was going to logout page when user reloads the page.
So I need bind the reload event also like the above js code for f5, submit and anchor tags.
Pleae help me in this regard.
Thanks in Advance...
Two things came into my mind:
First of all the fact that the user is logged in, doesnt mean that theres any activity going on, some people leave there pc turned on with the browser running.
Second is that even if the user closes a page it doesnt necesserly means that he/she wanted to logout and its especially true if the user use two tab to navigate on your site.
So instead of trying to check when they close the tab I suggest considering the idea of logging them out only when they login from somewhere else and/or setting up a timer that automatically log them out after a certain amount of inactivity.

Facebook Connect - Android

I'm following the following tutorial for Facebook Connect:
https://developers.facebook.com/docs/mobile/android/build/
And attempting to allow my users to login via Facebook. Right now, I'm successfully rendering a permission request / login box, but the language, according to Google Translate, is Indonesian. I can see nowhere in my FB App settings to change this, and nowhere in the FB-Connect source to change this. I've tried not only my Inspire 4g, which has a custom ROM, but also a stock Galaxy Tab.
Has anyone encountered this before?
EDIT: Additionally, the app is attempting SSO (single-sign-on), aka, it's using the installed Facebook application to do the authorization, so I can't just tack on the locale to the end of the API URLs, as it's not using them. I will need to do that if the user doesn't have Facebook installed, but right now I'm trying to get SSO working.
Here is the relevant section of code from the FB API that calls the FB App. I imagine that somewhere within I need to request my specific locale:
private boolean startSingleSignOn( Activity activity, String applicationId, String[] permissions, int activityCode )
{
boolean didSucceed = true;
Intent intent = new Intent();
intent.setClassName( "com.facebook.katana", "com.facebook.katana.ProxyAuth" );
intent.putExtra( "client_id", applicationId );
/** perhaps here, I need to add to the Intent? **/
if( permissions.length > 0 )
{
intent.putExtra( "scope", TextUtils.join( ",", permissions ) );
}
// Verify that the application whose package name is
// com.facebook.katana.ProxyAuth
// has the expected FB app signature.
if( !validateActivityIntent( activity, intent ) )
{
return false;
}
mAuthActivity = activity;
mAuthPermissions = permissions;
mAuthActivityCode = activityCode;
try
{
activity.startActivityForResult( intent, activityCode );
}
catch( ActivityNotFoundException e )
{
didSucceed = false;
}
return didSucceed;
}
This looks like an issue with Facebook:
Facebook Authorize App dialog displayed using incorrect locale

Categories