Remove back button if platform is Android - android

i have a problem in my app. (i'm using Ionic v1)
I want to hide the back button if the platform is Android, but if is iOS i want to show it.
I have the following code:
.config(function($ionicConfigProvider, $urlRouterProvider) {
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/login');
if (ionic.Platform.isAndroid()) {
$ionicConfigProvider.tabs.style("tabs-icon-top tabs-striped");
$ionicConfigProvider.tabs.position("top");
$ionicConfigProvider.navBar.alignTitle("center");
}
else if (ionic.Platform.isIOS()) {
$ionicConfigProvider.backButton.text('').icon('ion-arrow-left-c');
$ionicConfigProvider.tabs.style("tabs-icon-top tabs-striped");
$ionicConfigProvider.tabs.position("top");
$ionicConfigProvider.navBar.alignTitle("center");
}
});
Thank you!

Put your code inside $ionicPlatform.ready method:
$ionicPlatform.ready(function(){
if (ionic.Platform.isAndroid()) {
$ionicConfigProvider.tabs.style("tabs-icon-top tabs-striped");
$ionicConfigProvider.tabs.position("top");
$ionicConfigProvider.navBar.alignTitle("center");
}
else if (ionic.Platform.isIOS()) {
$ionicConfigProvider.backButton.text('').icon('ion-arrow-left-c');
$ionicConfigProvider.tabs.style("tabs-icon-top tabs-striped");
$ionicConfigProvider.tabs.position("top");
$ionicConfigProvider.navBar.alignTitle("center");
}
});

Related

include line only if platform is Android

One problem that I have is that when I navigate to a page containing a form on android the keyboard pops up automatically. I found a solution for it but it only works on Android:
import { View } from "tns-core-modules/ui/core/view";
export class AutoFocusView extends View {
createNativeView() {
if (typeof android !== "undefined") {
const linearLayout = new android.widget.LinearLayout(this._context);
linearLayout.setFocusableInTouchMode(true);
linearLayout.setFocusable(true);
return linearLayout;
}
return super.createNativeView();
}
onLoaded() {
super.onLoaded();
this.requestFocus();
}
requestFocus() {
const nativeViewProtected = this.nativeViewProtected;
nativeViewProtected.requestFocus();
}
}
I use this component. but it only works on android so I need to comment it from my code everytime I want to build for IOS. I was wondering if there was an easier way.
You could do like this:
import {isAndroid, isIOS} from '#nativescript/core';
then in your computed:
isandroid() {
return isAndroid;
}
then use this flag in any method you need:
if(isAndroid) {
this.requestFocus();
}
You also can use this isAndroid flag in your template if need be with v-if.
Just call requestFocus() only if platform is Android.
onLoaded() {
super.onLoaded();
if (typeof android !== "undefined") {
this.requestFocus();
}
}
You may also write it as a plugin within project, separate code for iOS and Android in platform specific file.

How to detect user screenshot action in flutter?

How can I detect if the user creating a screenshot?
I do not care about the capture pictures, I just want to know when and where user creating the screenshot
How can I detect this in the flutter app?
You can try this plugin, it might be what you are looking for: https://pub.dev/packages/screenshot_callback
In order to accomplish what you are looking for from the README:
import 'package:screenshot_callback/screenshot_callback.dart';
ScreenshotCallback screenshotCallback = ScreenshotCallback();
screenshotCallback.addListener(() {
//Void funtions are implemented
print('detect screenshot');
});
try
https://pub.dev/packages/screenshot_callback
dependencies:
screenshot_callback: ^1.1.3
void init() async {
await initScreenshotCallback();
}
//It must be created after permission is granted.
Future<void> initScreenshotCallback() async {
screenshotCallback = ScreenshotCallback();
screenshotCallback.addListener(() {
setState(() {
text = "Screenshot callback Fired!";
});
});
screenshotCallback.addListener(() {
print("We can add multiple listeners ");
});
}

How to identify back button event in Xamarin cross-platform (Xamarin.Forms)

Is there any way to know when the 'back' button event on the 'Android phone' is pressed? I'd like to exit the game and add few functionality to it when this button is pressed in Xamarin.Forms.
I googled a bit regarding this, but I got articles regarding Xamarin.Android Back button but not for Xamarin.Forms.
As I am relatively new to Xamarin.Forms, please help me out
public override void OnBackPressed()
{
//base.OnBackPressed();
}
Same thing I want in Xamarin.Forms. Need some assistance, guys.
If you mean Xamarin.Forms by "Xamarin Cross Platform", there is a OnBackButtonPressed event that you can use. As seen on that documentation:
Event that is raised when the hardware back button is pressed. This
event is not raised on iOS.
Simply override this event on your NavigationPage and you're ready to go:
protected override bool OnBackButtonPressed()
{
// Do your magic here
return true;
}
Good luck!
In my xamarin forms app you need to find the NavigationStack of the current Page if you are using master page:
public bool DoBack
{
get
{
MasterDetailPage mainPage = App.Current.MainPage as MasterDetailPage;
if (mainPage != null)
{
bool doBack = mainPage.Detail.Navigation.NavigationStack.Count > 1 || mainPage.IsPresented;
//top level of page and the Master menu isn't showing
if (!doBack)
{
// don't exit the app only show the Master menu page
mainPage.IsPresented = true;
return false;
}
else
{
return true;
}
}
return true;
}
}

Back button behavior within an InAppBrowser window with Cordova 3.6?

I'm writing a mobile application using cordova 3.6, this app just open an external url corresponding to the mobile version of my website
var ref = window.open('http://www.stackoverflow.com', '_self', 'location=no');
If a use _self as the target, the back button behavior is fine forme as it works correctly within browesed pages but the problem is that the last back in the history stack done go back on my index page and then open once again my url ! Also the events on the window doesn't work. How to exit?
var ref = window.open('http://www.stackoverflow.com', '_blank', 'location=no');
If a use _self as the target, the back button behavior is not the same. There is no back possible within browsed pages, just a back on the index page whatever we are. How can I modify the behavior to have the same as the _self?
I am stuck with these 2 solutions :(
Note: I saw this similar question but the suggested code
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
closeDialog();
}
});
no more exists in cordova InAppBrowser.java no more exist
I found a working solution for the "_blank" option target using cordova 3.6 thanks to the answer of Kris Erikson on this post
With those modifications the hardware back button works within pages in an InAppBrowser.
I copy hereafter his working solution
Go to src/com/org/apache/corodova/inappbrowser directory and edit the InAppBrowserDialog.java:
Change
public void onBackPressed () {
if (this.inAppBrowser == null) {
this.dismiss();
} else {
// better to go through the in inAppBrowser
// because it does a clean up
this.inAppBrowser.closeDialog();
}
}
to
public void onBackPressed () {
if (this.inAppBrowser == null) {
this.dismiss();
} else {
if (this.inAppBrowser.canGoBack()) {
this.inAppBrowser.goBack();
} else {
this.inAppBrowser.closeDialog();
}
}
}
Then go to InAppBrowser and find the goBack function, change:
/**
* Checks to see if it is possible to go back one page in history, then does so.
*/
private void goBack() {
if (this.inAppWebView.canGoBack()) {
this.inAppWebView.goBack();
}
}
to
/**
* Checks to see if it is possible to go back one page in history, then does so.
*/
public void goBack() {
if (this.inAppWebView.canGoBack()) {
this.inAppWebView.goBack();
}
}
public boolean canGoBack() {
return this.inAppWebView.canGoBack();
}
Please post if you find a better solution avoiding to modify the java code

AngularJS back button

I'm working on making an Android app using Phonegap and AngularJS. I'm attempting to create a button to be used as both a "cancel" and a "back" button, that will essentially just hit the browser's 'back' button.
Here's some sample HTML for the cancel button:
cancel
And here is the controller for that page, with the goBack() button:
function NewOccasionCtrl($scope, $window) {
$scope.$window = $window;
$scope.goBack = function() {
$window.history.back();
};
}
This throws no errors, but also doesn't work... the emulator remains on the same page. Without the $scope.$window = $window it throws an error. I was hoping to achieve a functional 'back' button without having to create/use a directive, because as far as I understand those then implement templating and things I don't need/want.
Is there a way to do this? Thanks
I went with using a Directive to make the back functionality reusable. Here is my final code:
HTML:
<a href back-button>back</a>
Javascript:
app.directive('backButton', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('click', goBack);
function goBack() {
history.back();
scope.$apply();
}
}
}
});
I had an issue like this using phonegap and angular, $window.history.back() would not work. So I created a workaround.
$scope.urlHistory = [];
$scope.$on('$routeChangeSuccess', function () {
if ($location.$$absUrl.split('#')[1] !== $scope.urlHistory[$scope.urlHistory.length - 1]) {
$scope.urlHistory.push($location.$$absUrl.split('#')[1]);
}
});
$scope.goBack = function () {
$scope.urlHistory.pop();
$location.path($scope.urlHistory[$scope.urlHistory.length - 1]);
};
Hope this help someone else.

Categories

Resources