Difficulty running on Android

Hi
I have this very simple code:

<head>
  <title>mobile-render-test</title>
</head>

<body>

     {{> home}}

</body>


<template name="home">

	{{#if Meteor.isCordova}}
		{{> mobile}}
	{{else}}
		{{> web}}
	{{/if}}

</template>

<template name="mobile">

	<h1>Cordova</h1>
	<p>This is rendered in the mobile device.</p>

</template>

<template name="web">

	<h1>Web</h1>
	<p>This is rendered in the web browser.</p>

</template>

I use “meteor run android-device” and I can access it at localhost:3000 in a web browser as normal, and it shows me Web - This is rendered in the web browser", but on my Android device, it shows exactly the same ie: “Web - This is rendered in the web browser” instead of “Cordova - This is rendered in the mobile device”

What am I doing wrong?

My Android device is a Samsung Phablet SM-T705Y (tablet phone)

Could it be registering as having a larger screen than a phone? Its a 7" phablet, not an iPhone etc.

It gives the same “Web - This is rendered in the web browser” when running on my Samsung Galaxy Tab SM-T530

Does anyone have any ideas?

Thanks!

Have you tried making this boolean a helper?

Something like:

Template.home.helpers({
    isMobile: function() {
        return Meteor.isCordova;
    }
});

And then:

<template name="home">
{{#if isMobile}}
	{{> mobile}}
{{else}}
	{{> web}}
{{/if}}
</template>

Not sure how these built-in functions work on Spacebars.

Thanks very much Rafael!
That worked!
But honestly, I really thought I did that - but got a “Template not found” error message.
Anyway, thanks again!

Just an update: one thing I found…

The:

Template.home.helpers({
    isMobile: function() {
       return Meteor.isCordova;
    }
});

needs to be wrapped inside:

if ( Meteor.isClient ) {
}

So it needs to be:

if ( Meteor.isClient ) {
    Template.home.helpers({
        isMobile: function() {
           return Meteor.isCordova;
        }
    });
}

in the .js file.

And another aside, just adding that to an already running project, does not update the client device.
You have to ^C and restart with meteor run android-device

That’s what I found. Hope this was helpful for someone.

Now I’m off to look at this: (!)

Thanks again Rafael.

1 Like

It is best to have all templates, and JS files for templates (helpers etc…) within a folder called ‘client’ so that you don’t need the conditional code to check if its the client.
Also means the server won’t have that code packaged and skipped over constantly.

Thanks for that tip Chris. This was just a proof of concept not a working app - just to get a feel for it all, but yes you’re right.
How’s Sydney? Have you ever been to a Meteor Meetup there?
Cheers
Brad

No worries, took me a while to get my head around files and folders and what I thought worked best for me. Wasn’t sure if you were still testing the waters :smile:

Yeah Sydney is Amazing this time of year, cold but beautiful.
Never been to a meet-up before.

Where are you from?

Yes it was just a real quick test :smile:

I’m in Brisbane.
I have started the Brisbane Meteor Meetup and have had one meetup so far. Next one is May 25 (tentative at this stage)

Anyway, the football is almost on - Broncos v Penrith!

1 Like