Wednesday, February 4, 2015

How to stop Bluetooth auto play feature when connecting your phone to your car.

Last year I bought a Toyota car that came with the Toyota Entune system. In the first few hours of owning the car, I tried pairing my HTC One M8 to it so I could stream my music via BlueTooth and it worked pretty well. I could finally abandon my AUX cable and life was good.

Then after a few days, I started finding a few annoyances, for example, I found out that every time I got in my car, Entune would send a "play" signal to my phone during pairing and my phone would start playing music without me asking for it. I would see myself turning the radio off as soon as I got in the car every single time.

While turning the radio off solved the problem, it also broke other things like google maps for navigation or any other app that streams sounds via Bluetooth. I want to hear the navigation directions so turning off the radio also killed that option.

A few months go by and I'm really fed up with the way this works. I scheduled a visit @ my Toyota dealer and ask them to update my Entune software thinking that they would have issued a fix or at least an option to disable that "feature". To my disappointment, there was no fix to the problem. As soon as I got in the car after the update, my phone started playing music automatically and there was no option to disable it. I even called the Entune support line and asked if there was anything that I was missing but nothing was suggested.

That was the time I started searching for an alternate solution to the problem. Entune wasn't going to fix it, so I had to find a fix myself. I even thought about writing something for Android to prevent the auto play feature, but before I sat down to code it, I found a few posts online that were promising.

During my research, I found out that many people had the same issue and it dated back a few years including the first Entune versions. I found many threads with people complaining about the problem.

After trying many apps and ideas, the solution that solved the problem for me is the following:

You need the following apps installed on your phone:
  1. Media Button Router
  2. Disable Autoplay
Once you have those 2 apps installed on your phone, open Media Button Router and deselect all auto play apps except Disable Autoplay. This will make sure that the only app triggered during the Bluetooth pairing with your car is the Disable Autoplay app.
Also, in Disable Autoplay, select click on "Disable Media Button".

This is all there's to it. Now, every time I get in my car, my music doesn't auto play anymore but things like navigation directions or streaming works without any manual intervention.

I hope this helps anybody who'd been having problems with their Entune system or any other Bluetooth system that insists in auto playing music every time you connect to it.

Until next time...

***** Update *****

There's now a better and simpler way to stop autoplay on Bluetooth connect:

Bluetooth Connect & Stop Play

On my new phone (Google Pixel XL) it works flawlessly while the previous solution doesn't work anymore... 😜

Thursday, October 4, 2012

XBOX Phone

XBOX Phone Concept
 A little over a year ago, I posted a suggestion on the Windows Phone forum asking Microsoft to consider creating an XBOX Phone.

I started developing Windows Phone applications before the phone was officially released. I wanted it to succeed really bad, after all, C# is my favorite language and the .NET environment is IMHO the best way to develop applications hands down.

Well, a year has gone by and Microsoft is still struggling trying to get any market share. Will they succeed in trying to beat Android or iOS? It's too early to say.

One area where they dominate is Video Games. They are a really strong player in the console world, but they are lacking a handheld version of their XBOX console, so why not use that success to catapult themselves where no other phone has been able to compete?

If I were Microsoft, I'd be jumping on that idea right now! Phones like Xperia Play have failed to get a good amount of buyers, but that's because they created a sub-par phone. I wanted to buy one so bad, but when I played with it at the store, I was extremely disappointed. Had it been a different story, I probably would be playing my favorite emulator right now on my phone...

Maybe the time has come and Microsoft might already be working on this according to this patent. Time will tell!

Now, I use a Galaxy Nexus and I'm liking it more and more. If Microsoft waits too long to come up with something good / different / interesting, it may lose the phone battle forever...

Wednesday, October 3, 2012

Success - How Bad Do You Want It?

I've been thinking a lot about my definition of success lately and came across this video. I think it says it all:


Sometimes we need a wake up call to see what's really important in our lives and what legacy we want to leave behind...

Monday, October 1, 2012

Don't drink the Methodology of the Day Kool-Aid

I work with some of the largest amount of data on Earth


In the Enterprise world, it's no doubt that Java has been very successful. Java has invaded corporations like there's no tomorrow, promising reusable code, developer support and frameworks that make web development for the enterprise one of the best of its class.

A little bit of Background


Before joining a FORTUNE 50 company, I was the biggest adopter of the "Development-Driven-Development" methodology. (Don't worry. That methodology doesn't actually exist), but it gets my point across perfectly. I left Wolfram Research as a Software Engineering Manager. My team was used to creating and delivering products very fast. We were doing so good that I was promoted twice in the same year and 5 times in 4 years. It was a great feeling of getting things accomplished and being able to move on to the next target.

My team was creating something beautiful. It all started with a series of Import and Export plugins for Mathematica. After a while, the team expanded to Import and Export, Data Curation, and the Image Processing team which I managed. Together, these teams basically created what is Wolfram Alpha today (the backend part at least). We went from being able to import GIF and a few other raster images to a steam powered machine that could import almost any format in almost any field such as 3D models, spreadsheets, Bioinformatics, etc. We were also able to "Rasterize" any type of Mathematica expression into a Raster image which is still the method of generating images in Wolfram Alpha today.

Why am I telling you all of this? Because coming from a fast-paced environment where new things happened everyday to a FORTUNE 50 company was like night and day for me. Things like innovation, creativity and motivation were replaced by process, methodologies and frameworks.

The reality of a corporation


A Corporation's IT sector cares deeply about HOW to do things. They are not so much focused on being cutting edge as they are in creating ways that can be easily reproduced and how to provide support for these solutions in the long run. It looks for cookie-cutter software implementations that can be executed and maintained by ANYONE even when the paradigm doesn't apply. They believe in this way of doing things so much that they are willing to adopt almost any kind of framework or methodology that promises to create a process around a solution. What I mean by that is that once a vendor gets in the door, they will be able to sell almost anything else. All they have to do is throw in a few buzzwords and it's adopted. That's the goldmine of the IT industry: Being a preferred vendor for a large corporation.

Back to the subject...


Suddenly I went from creating cutting edge applications to having meetings about which framework was in fashion that day or how we could use the newest Spring Loaded Inversion of Control Toolkit. Applications became so bloated that something that I could write in one week by myself at home would take 10 people more than 1 year to create. People were obsessed with the buzzwords and were willing to do anything to start using the newest technology just so that they didn't have to write real code.

I was getting desperate. I couldn't agree with 99.9% of what my leaders were saying and I had no way to fight against them. In the old world I could tell my VP or CEO my idea was better than theirs and they would listen to me (as long as I could back what I was saying), as for the new world, technical expertise doesn't matter if you don't fit the mold. You may be the brightest Engineer in the room, but when someone with a higher pay-grade says something, it's written in stone and can't be changed. It's a world were admitting you are wrong or somebody has a better idea than you is a sign of weakness and a sign of weakness prevents you from climbing higher in the management ladder. I can name several occasions where a superior product was questioned and vetoed because it wasn't on the approved software list / framework / language. Some times I think this is actually the perfect plot where the goal of a vendor is to make a solution as complex as possible so they can keep sucking the blood of the company for years to come.

The best example I've been part of is a project where a C# application, which was originally written as a single class, needed to be converted to a Java / WebSphere application. After a whole year of coding and 4 developers working full time, the application required 15 JVMs on 15 different servers across the country and things ran as slow as a one-legged turtle. The great thing about it was that it had the latest technology, Dependency Injection for everything, and functions written exclusively for OR comparisons. Testing this application was a nightmare. Testers needed to get 7 levels deep in the code just to see how something worked. Eventually once people realized what had happened, it was too late to turn back.

This is about the time I learned about the Spring Framework and Injection. In theory it might be an awesome idea, but Dependency Injection is not useful in practice, trust me. Dependency Injection makes an application so complicated with all the XML configuration files all over the place that the time it might save you from recompiling your app when you want to change something will be multiplied by 1000x when servicing this same application. Of course I speak from personal experience, but I've lived on the cutting edge and now I live in the conservative world. I know very well what produces results and what costs money.

Time and time again I see that developing in an environment like this is like running a marathon with your legs tied. While the latest buzzword promises to make applications easier to develop, they will make developers cry when they have to maintain this type of code and I guarantee that it will take at least 3 times more resources.

To summarize


Don't take the new buzz words out there as the holy grail of development, be it Test-Driven-Development, Design-Driven-Development, Dependency Injection, Inversion of Control, etc. Analyse what your application needs. Talk to your customers. Think of how to service it and think of what you are trying to achieve. Everything has a place, but while knowing these things might make your resume look nice, they may not be the best way to solve the problem at hand.

Tuesday, September 25, 2012

Calling Web Services Using BasicAuth From .NET

At work I have to consume lots of web services from all over the place. They come in many flavors: .NET, Java, etc.

When calling Java Web Services written in WebSphere from .NET using BasicAuth (username and password), sometimes the credentials are not asked from the host and the return code is a 401:

Web Exception

The best way to fix this annoying problem is to create a partial class with the same name as the one generated by WSDL.exe and override the GetWebRequest(Uri uri) function.

Creating a Web Service Client:

WSDL.exe

Creating partial class with overridden method: 

public partial class Service
{
    public string Username { get; set; }
    public string Password { get; set; }

    private void setBasicAuthHeader(WebRequest req)
    {
        string authInfo = Username + ":" + Password;
        authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
        req.Headers["Authorization"] = "Basic " + authInfo;
    }

    protected override WebRequest GetWebRequest(Uri uri)
    {
        this.Credentials = new NetworkCredential(Username, Password);
        WebRequest request = base.GetWebRequest(uri);
        setBasicAuthHeader(request);
        return request;
    }
}

The code above will override the GetWebRequest method by adding an "Authorization" header containing the username and password. WebSphere looks for this header on basic authorization. This should get rid of the 401 return code.

Calling the Web Service:

void CallService()
{
    Service service = new Service();

    service.Username = "username";
    service.Password = "password";

    Result result = service.GetData();
}

And this is all there is to it. Now you can call any web service that accepts basic auth.

Monday, September 17, 2012

Creating Interactive Charts with ASP.net MVC

Chart Control

Problem at Hand:

Many ASP.net developers are used to creating charts using the .NET built-in Chart Controls, but how about MVC developers? Are they out of luck?

A couple weeks ago I was looking for a way to generate nice looking charts for an application I'm working on and I found out that while there are several ways to use the .NET chart controls in MVC, most of the implementations lack interactivity and therefore were useless for the application I wanted to create. I found an example from Daniel A Hill using a custom chart action result and it looked promising, but it lacked interactivity as well, so I started looking for a way to make my own Action that would do what I wanted.

If we look at the underlying HTML that is generated by chart controls, we see that it consists of a <img> and a <map>, so all we need to do is create both of these and we will have our interactive controls.

Controller Action:

public ActionResult Chart()
{
    var chart = buildChart();
    StringBuilder result = new StringBuilder();
    result.Append(getChartImage(chart));
    result.Append(chart.GetHtmlImageMap("ImageMap"));
    return Content(result.ToString());
}

Utility Functions:

private Chart buildChart()
{
    // Build Chart
    var chart = new Chart();

    // Create chart here
    chart.Titles.Add(CreateTitle());
    chart.Legends.Add(CreateLegend());
    chart.ChartAreas.Add(CreateChartArea());
    chart.Series.Add(CreateSeries());

    return chart;
}

private string getChartImage(Chart chart)
{
    using (var stream = new MemoryStream())
    {
       string img = "<img src='data:image/png;base64,{0}' alt='' usemap='#ImageMap'>";
       chart.SaveImage(stream, ChartImageFormat.Png);
       string encoded = Convert.ToBase64String(stream.ToArray());
       return String.Format(img, encoded);
    }
}

Then in your View code:

@{ Html.RenderAction("Chart"); }

Conclusion:

This is all there is to it. One caveat is that you MUST call chart.SaveImage() before calling chart.GetHtmlImageMap(), otherwise it will throw an Exception, but if you are careful in doing that, it should all just work.To see an example of the new controller in action, head over to MVC Chart. To see the whole source code, take a look at my github repository.