Posts Tagged ‘android’

I ran into this issue today when debugging on Android, so posting what took an hour to figure out 🙂 This is for when you’re getting a null reference exception when attempting to scan. I was following the instructions here, and then, well, it wouldn’t work 🙂

Rather than using the Dependency Resolver, you’ll need to pass in the Application Context from Android. So, in the App, create a static reference to the IQrCodeScanner,, as follows:

	public partial class App : Application
	{
 
	    public static IQrCodeScanningService QrCodeScanningService;

Then, populate that static instance from the Android app, as follows:

App.QrCodeScanningService = new QrCodeScanningService(this);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());

Obviously you’ll also need a matching constructor, like so:

public class QrCodeScanningService : IQrCodeScanningService
{
    private readonly Context _context;
 
    public QrCodeScanningService(Context context)
    {
        _context = context;
    }

This solved the problem like magic for me. I hope it helps you, too!

P.S. Make sure you have the CAMERA permission. I’ve also read you may also need the FLASHLIGHT permission, although I’m not entirely sure that’s required.

As part of my .NET 301 Advanced class at the fantastic Eleven Fifty Academy, I teach Xamarin development. It’s sometimes tough, as every student has a different machine. Some have PCs, others have Macs running Parallels or Bootcamp. Some – many – have Intel processors, while others have AMD. I try to recommend students come to the class with Intel processors, due to the accelerated Android emulator benefit Intel’s HAXM – Hardware Acceleration Manager – provides. This blog entry is a running list of how I’ve solved getting the emulator running on so many machines. I hope the list helps you, too.

This list will be updated from time to time, as I find new bypasses. At this time, the list is targeted primarily for machines with an Intel processor. Those with AMD and Windows are likely stuck with the ARM emulators. Umm, sorry. I welcome solutions, there, too, please!

Last updated: December 4, 2017

Make sure you’re building from a path that’s ultimate length is less than 248 characters.

That odd Windows problem of long file paths bites us again here. Many new developers tend to build under c:\users\username\documents\Visual Studio 2017\projectname. Add to that the name of the project, and all its subfolders, and the eventual DLLs and executable are out of reach of various processes.

I suggest in this case you have a folder such as c:\dev\ and build your projects under there. That’s solved many launch and compile issues.

Use the x86 emulators.

If you have an Intel processor, then use the x86 and x64 based emulators instead of ARM. They’re considerably faster, as long as you have a) an Intel processor with virtualization abilities, which I believe all or most modern Intel processors do, and b) Intel’s HAXM installed.

Make sure VTI-X / Hardware Virtualization is enabled.

Intel’s HAXM – which you can download here – won’t run if the processor’s virtualization is disabled. You need to tackle this in the BIOS. That varies per machine. Many devices seem to chip with the feature disabled. Enabling it will enable HAXM to work.

Uninstall the Mobile Development with .NET Workload using the Visual Studio Installer, and reinstall.

Yes, I’m suggesting Uninstall + Reinstall. This has worked well in the class. Go to Start, then Visual Studio Installer, and uncheck the box. Restart afterwards. Then reinstall, and restart.

Mobile Development Workload Screenshot

Use the Xamarin Android SDK Manager.

The Xamarin team has built a much better Android SDK Manager than Google’s. It’s easy to install HAXM, update Build Tools and Platforms, and so forth. Use it instead and dealing with tool version conflicts may be a thing of the past.

Make sure you’re using the latest version of Visual Studio.

Bugs are fixed all the time, especially with Xamarin. Make sure you’re running the latest bits and your problems may be solved.

Experiment with Hyper-V Enabled and Disabled.

I’ve generally had issues with virtualization when Hyper-V is enabled. If you’re having trouble with it enabled, try with it disabled.

To enable/disable Hyper-V, go to Start, then type Windows Features. Choose Turn Windows Features On or Off. When the selection list comes up, toggle the Hyper-V feature accordingly.

Note: You may need to disable Windows Device Guard before you can disable Hyper-V. Thanks to Matt Soucoup for this tip.

Use a real device.

As a mobile developer, you should never trust the emulators to reflect the real thing. If you can’t get the emulators to work, and even if you can, you have the option of picking up an Android phone or tablet for cheap. Get one and test with it. If you’re not clear on how to set up Developer Mode on Android devices, it’s pretty simple. Check out Google’s article on the subject.

Try Xamarin’s HAXM and emulator troubleshooting guide.

The Xamarin folks have a guide, too.

If all else fails, use the ARM processors.

This is your last resort. If you don’t have an Intel processor, or a real device available, use the ARM processors. They’re insanely slow. I’ve heard there’s an x86 emulator from AMD, yet it’s supposedly only available for Linux. Not sure why that decision was made, but moving on… 🙂

Have another solution?

Have a suggestion, solution, or feature I’ve left out? Let me know and I’ll update!

 

Want to learn all about Xamarin and how you can use it, while not spending most of your time watching code scroll by in a video? I figured there was room for an explainer without being a close-captioner for a code tutorial. Enjoy my latest video!

https://www.youtube.com/edit?video_id=AhvofyQCrhw

From the description, along with links:

Have you been considering Xamarin for your cross-platform mobile app? This presentation will help.

In this non-code-heavy presentation, we’ll discuss:

* What is Xamarin
* Development Environment Gotchas
* Creating a Sample To Do List App without writing any code
* Reviewing a real Xamarin app that’s “in the wild”
* Review native, platform-specific integrations
* Discuss gotchas when using Xamarin, and mobile apps in general
* Answer audience questions

Why not code-heavy? Because there are many examples you can follow online. This presentation will provide valuable information you can consider while reviewing the myriad of tutorials available to you with a simple Bing or Google search, or visiting Pluralsight, Microsoft Virtual Academy, or Xamarin University.

If you have any feedback, please leave in the comments, or ask me on Twitter: @Auri

Here are the links relevant for this presentation:

Slides: https://1drv.ms/p/s!AmKBMqPeeM_1-Zd7Y…

Indy.Code Slides with Cost and Performance Figures: https://1drv.ms/p/s!AmKBMqPeeM_1-JZR4…
(you can find the Indy.Code() presentation on my YouTube channel)

Google Xamarin vs. Native iOS with Swift/Objective C vs. Android with Java Performance Article: https://medium.com/@harrycheung/mobil…

Example code for push notifications, OAuth Twitter/Facebook/Google authentication, and more: https://github.com/codemillmatt/confe…

Link to Microsoft Dev Essentials for $30/month free Azure credit and free Xamarin training: https://aka.ms/devessentials

Microsoft Virtual Academy Multi-Threading Series: https://mva.microsoft.com/en-us/train…

 

I’m continuing my resolution to record as many of my programming and technical presentations as possible. I recently spoke at the inaugural Indy.Code() conference. It was excellent, with an incredible speaker line-up. I hope they, too, post some of their presentations online!

Watch the Video on YouTube

From the synopsis:

Should you write your app “native”Âť or use a “cross-platform”Âť solution like React Native, Xamarin, or NativeScript? The new wave of native-cross-compiling solutions provide significant cost savings, code reuse opportunities, and lower technical debt. Does wholly native, per platform development, still play a role in future mobile development? Let’s discuss together.

In this presentation, we’ll discuss:

  • The growth of native, hybrid, and cross-platform mobile development solutions
  • Cost analysis of multiple native and cross-platform apps
  • Considerations for each native and cross-platform solution
  • Lessons learned

Slides are available here: https://t.co/5iLhEoEfen

If you have any questions, I’m happy to answer them! Please email me or ask on Twitter.

 

Alright, I found a Moto 360 and I’m enjoying it. The following is not my review. It is a list of bugs Motorola and Google need to fix on this device and across Android Wear. Note this is only what I’ve noticed after one day. I’ll post more as I explore.

  • When you take the phone out of the box, it doesn’t turn on or has a low battery. That’s understandable. What’s not alright is no prompt about the battery level or what to do. It’s simply “Connect your device to Android Wear,” or something to that effect. That’s very un-user-friendly. Where were the UX guys with the setup process?
  • Only one watch face shows the date. $250 and no date? Seriously?
    • Update, thanks to Rich DeMuro: Drag down slightly to see the date.
  • When asking the watch to make a call to a contact with more than one number, it asks "Which One?" However, it doesn’t give you a list. Saying "the first one" works, but I don’t know what I selected until it dials.
  • There’s no confirmation request when sending a text… it just sends it.
  • It sometimes stops listening or lists your options when listening.
  • It sometimes starts listening when it shouldn’t.
  • Carrier messaging apps break the ability to reply to texts. I had to disable Verizon Messaging entirely.
  • Facebook support for displaying the new comments would be nice, like the email display feature.
  • There’s no battery level meter anywhere on the device, or at least that’s obvious.
    • Update, thanks to Rich DeMuro: Drag down slightly from the top to see battery level.
  • The Android Wear app doesn’t show battery level, but Moto Connect does. Weird?
  • Sometimes Google search results take precedence over actions. For example, saying "play ebay by weird al" brings up YouTube results. However, "play technologic by daft punk" plays the song. It’s hit or miss.
  • So far, adding a calendar entry hasn’t worked.
  • There needs to be a notification center to control which notifications are sent to the phone. Yes, you can do it via the App Manager, but it’s horrible.
  • The accelerometer doesn’t always sense the wrist has been moved to a viewing angle.
  • When driving, the accelerometer appears to trigger the display to turn on *a lot*. It’s not good when driving kills your battery.
  • A speaker would be helpful for prompts.

Added 9/15 afternoon:

  • The Motorola Feedback website doesn’t list the Moto360 as a product. So, how do I register it or get support?
  • The device occasionally says its Offline when the phone is only three feet away. I’m thinking this is a bug in the Google Now integration and not an actual communications issue.
  • Asking the device "What is the battery level" always causes the phone to report it’s offline

Added 9/17:

  • Saying “Call <insert name here> on cell” doesn’t work most of the time, but saying the same “on mobile” is generally reliable.
  • Calling “Send text to <insert name here>” sometimes asks “Which one?” but only shows the phone numbers. I wasn’t sure if I was sending to the right person because the name wasn’t listed.
  • Most of the time, when the screen turns on when moving even the slightest, the watch starts listening, even if I don’t say “Ok, Google”. It’s very annoying.
  • It would be nice if “Ok, Google” could be changed to something else. I feel like I’m advertising Google every time I use my watch.
  • The pedometer seems inaccurate, rendering phantom steps as far as I can tell. The inaccuracy extends to the heart rate monitor. After a long workout, the monitor said I was at 74 bpm, then 90. I took my own pulse, and it was quite off the mark.

Added 9/30:

  • The latest build, 4.4W.1 KGW42R, has greatly improved battery life. On an average day of use, unplugging the watch at around 7am, I was still at 20% at roughly 9:45pm. Great job, Motorola!
  • Even with Messaging as the default app, I have no option to Reply to texts when the notification appears. This may be due to HTC overriding some default app, but I’m unsure.

A few tips:

To launch apps, go to the Google screen, then go to Start… and you can select an app.

You can say the following things and it’s really cool:

  • Call <person’s name> on mobile
  • Play the song <song name>
  • Play the song <song name> by <artist name>
  • What is the current stock price of <company name>

Ok, learned this sort of the hard way today… I picked up the brand spanking new HTC One M8 yesterday. So far it’s a fantastic phone. I wanted to add a 32 GB MicroSD card, since it wonderfully supports such expansion. Beware! There’s a little tray that comes out when you use the paper clip in the little hole. Put the MicroSD card in that tray! I thought it was simply a placeholder at first, so I slyly proceeded to simply insert the card into the hole. Whoops!

imageIf you fall into the same trap, it’s easy to get the MicroSD card out. First, you might as well finish the formatting steps – it’s in there anyway. When that’s done, use the paperclip to release the MicroSD card from the tray. Yes, I know it won’t come out all the way. After releasing it via the eject hole, use the side of the paperclip to gently pull the card out from the right side a little bit. Once you can see the plastic of the card, pull it out the rest of the way with your fingers. Problem solved!

Good luck!

-Auri