Thursday, October 20, 2016

Google Fit Integration Pedometer Data -Step by Step and Issues-


  1. Use History API for sending step count to google fit.
  2. Geneate Auth 2.0 ID by following steps in the below given Link. https://developers.google.com/fit/android/get-api-key
    1. While you are in debug mode no need to bother about debug certificate
    2. Follow steps from the heading  :- Request an OAuth 2.0 client ID in the Google API Console
    3. To get SHA-1 certificate follow steps in this link http://stackoverflow.com/questions/27609442/how-to-get-the-sha-1-fingerprint-certificate-in-android-studio-for-debug-mode
    4. Use your applications base package name which is available in manifest
    5. After creating key leave it . No need to copy it or configure it in project files like manifest or gradles. 
  3. Make sure FitnessAPI is enabled. This can be verified at dashboard of your project in google api console
  4. Start with copying sample code in to your Activity. Activity must be derived from ActivityFragment or AppCompactActivity . Otherwise it is not possible to use enableAutoManage. If you are not using that you have to many extra steps to connect with google accounts etc.
  5. If you are getting  ConnectionResult -> CANCELLED then there is chances your package name not correct
  6. if you are getting  statusCode=Application needs OAuth consent from the user then you are missing some scope 

.addScope(new Scope(Scopes.FITNESS_LOCATION_READ))
.addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))



Tuesday, February 21, 2012

Future of(is) Android

Hi All,
  I have some thoughts about a new trend in the technology. I though it it is worth sharing it here and probably it may help some people in the industry similar to mine.
  I am always facinated with developing application that is a mix of software and hardware.On one hand it gives me great amount of satisfaction and on the other hand it is little difficult to pirate as you need skill in both area.But as a small scale device manufacturer we always faced a big issue that we dont have enough finance backup to create beautiful looking moulds for our products.We are actually struggling with this issue and looking for funding to go ahead with our product development dreams.
 
There comes the revolution of tablets. Thanks to steve jobs!!!!. When I saw it in the market for the first time, I was excited. Not for the purpose they are introduced for , but in future they are going to solve my issue. iPad and Apple definitely not a choice for me , with their pricing strategy they are meant for rich men and only useful as a mobile device. But I was sure that clones will soon come. And that happened with Android.Android tablets starts emerging in the market. Still I have to wait as the first ones are too expensive. Finally the time came , I have noticed an advertisement in some site that a company named Wespro is offering tablets in indian market just for 5999/- . I realised that it is time or me to jump in.
Here is the solution for my problem....!!!!!!
All these years I faced problem for investing big amounts in molds. Now these cheap android tablets can solve my issue. How ??
Yes they can act as the pretty face of my product. I can now happily keep my product packed in an average box and use android tablet as the user interface device. We have soon ported all our applications in to android quickly with the rich API provided.

      With our resources and fanacial capability we coudnt think of customizing android tablet hardware itself. But I assume big players will defintely do that and android tablet hardware can definitely replace the custom touch screen products available in the market. Who could resist the rich hardware and a powerful API for developing emebeded solutions.

      I assume that we will soon see the emebeded landscape moving in to android platform. If that happens the coming decade we will see all android powered equipments.
      Imagin that your washing machine , oven, fridge, AC, HVAC etc programed from your wall mounted android tablets. I would suggest that it is high time for industry to consider equiping all device with a wifi module and common plug and play protocol. Such a protocol will allow a wall mount android to discover all your home equipments and render UI for controlling all those equipment with a common UI.
        It is my perception that our switch boards and electrical pannel will eventually replaced with android tablets.
If you are curious what product we did with Android please visit www.smartgardtab.com
BMJO

Thursday, October 6, 2011

Steve Jobs Vs Bill Gates

http://gizmodo.com/5838847/steve-jobs-is-dead




Actually I don't agree that Steve jobs made all these wonders for "third world" countries.



How many of us have this wonderful iPhone in our pocket!!!. It is those Chinese made mobiles affordable for all "cattle class" and their iPhone 5 will fit our pocket.



It is Bill gates and his liberal attitude towards piration made it possible to all middle class have a computer at their home with pirated windows running on it:):). Microsoft liberal piracy attitude made it possible for all those little training schools to run and teach all indians with basic ,c and ready for the IT jobs. Most of all those jobs on microsoft platform and created new creamy middle class in India. As I am on the receiving end and enjoying it I am more thankful to Bill Gates rather than Steve Jobs. If there is only Steve Jobs and no Bill gates all this will not happen. Even now if I need to start working on iPhone programing I need to pay an upfront 100$. How many indian /chinease hobbiest can spend that sum. I think he is missing a Vision here.



Dont think that I hate Steve Jobs:):). I know it is his vision about tablet made all these revolutionary change in computing Industry. (Remember Bill gates try to do that 10 years ago .Bad timing!!!) What made me happy about all these things is the Android +Tablet combination. We have a cheap programmable mobile platform out there which can make automation revolution.

Tuesday, October 4, 2011

Cloud evaluation for a Socket Server Application (Amazon AWS vs Windows Azure vs Google AppEngine)

Recently I made a little research on clouds for an application which we are planning to develop. This one is a server application which need to listen for clients on a socket. We also need to send vedeo audio streams back and forth. Client application may run on Windows, android and iOS. So we decided to use raw sockets and custom streaming. Then we were trying decide which cloud to be used. Finally I decided on AWS ans use .Net and MySQL to build our server. Here is the comparison chart I created if it is helpful to anybody.


 Link to Spread Sheet with comparison

Wednesday, August 31, 2011

MCI : Complete Recorder and Player Class


#region NameSpace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
#endregion

namespace EBAudioControl
{
public class Player
{
#region Fields
public long test = 1;
Random randomNumber = new Random();
private StringBuilder msg; // MCI Error message
private StringBuilder returnData; // MCI return data
private int error;
private string Pcommand; // String that holds the MCI command
private ListView playlist; // ListView as a playlist with the song path
public int NowPlaying { get; set; }
public bool Paused { get; set; }
public bool Loop { get; set; }
public bool Shuffle { get; set; }
[DllImport("winmm.dll")]
private static extern int mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
[DllImport("winmm.dll")]
public static extern int mciGetErrorString(int errCode, StringBuilder errMsg, int buflen);
#endregion

public enum Position
{
Begining,
Current
}

#region Constructor
public Player()
{

NowPlaying = 0;
Loop = false;
Shuffle = true;
Paused= false;
msg = new StringBuilder(128);
returnData = new StringBuilder(128);
}
#endregion

#region Methods

public void Close()
{
Pcommand = "close sounddev";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
}

public bool Open()
{
Pcommand = "open new Type waveaudio Alias sounddev";
error = mciSendString(Pcommand, returnData, 128, IntPtr.Zero);
if (error == 0)
return true;
else
return false;
}

public bool Load(string sFileName)
{
Close();
// Try to open as mpegvideo
Pcommand = "open \"" + sFileName + "\" type mpegvideo alias sounddev";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
if (error != 0)
{
// Let MCI deside which file type the song is
Pcommand = "open \"" + sFileName + "\" alias sounddev";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
if (error == 0)
return true;
else
return false;
}
else
return true;
}

public bool LoadNPlay(string fileName)
{
if (Load(fileName))
{
Pcommand = "play sounddev";
error = mciSendString(Pcommand, null,0, IntPtr.Zero);
if (error == 0)
{
return true;
}
else
{
Close();
return false;
}
}
else
return false;
}

public bool Save(string fileName)
{

Pcommand = "save sounddev " + fileName;
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
if (error == 0)
{
Close();
return true;
}
else
{
Close();
return false;
}

}

public bool MoveToEnd()
{
int pos = GetLength();
Pcommand = "seek sounddev to " + pos.ToString();
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
if (error == 0)
{
return true;
}
else
{
return false;
}
}

public bool MoveToBegin()
{
Pcommand = "seek sounddev to 0";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
if (error == 0)
{
return true;
}
else
{
return false;
}
}

public bool MoveBack()
{
int pos= GetCurentMilisecond();
if (pos > 5000) pos -=5000;
else pos = 0;
Pcommand = "seek sounddev to " + pos.ToString();

error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
if (error == 0)
{
return true;
}
else
{
return false;
}
}

public bool MoveForward()
{
int pos = GetCurentMilisecond();
int length = GetLength();

if (length > (5000 + pos)) pos +=5000;
else
{
return false;
}
Pcommand = "pause sounddev ";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);

if (error != 0)

{
return false;
}

Pcommand = "seek sounddev to " + pos.ToString();

error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
if (error == 0)
{
return true;
}
else
{
return false;
}
}

public bool PlayFrom(Position pos)
{
if (pos != Position.Begining)
{
if (GetLength() == GetCurentMilisecond())
{
Pcommand = "play sounddev from 0";
}
else
Pcommand = "play sounddev";
}
else
{
Pcommand = "play sounddev from 0";
}
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
if (error == 0)
{
return true;
}
else
{
return false;
}
}

//public bool Play(int track)
//{
// if (Open(playlist.Items[track].SubItems[1].Text))
// {
// Pcommand = "play sounddev";
// error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
// if (error == 0)
// {
// NowPlaying = track;
// return true;
// }
// else
// {
// Close();
// return false;
// }
// }
// else
// return false;
//}

public void Pause()
{

if(IsPlaying()||IsRecording())
{
Pcommand = "pause sounddev";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
Paused = true;
}
}
//public void RecordPause()
//{
// error = mciSendString("pause sounddev", null, 0, IntPtr.Zero);
//}
public void Stop()
{
Pcommand = "stop sounddev";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
Paused = false;
Close();
}

public void Resume()
{
Pcommand = "resume sounddev";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
}

public bool Record()
{
error = mciSendString("set sounddev bitspersample 16", null, 0, IntPtr.Zero);
error = mciSendString("set sounddev samplespersec 44100", null, 0, IntPtr.Zero);
Pcommand = "record sounddev";
error = mciSendString(Pcommand, null, 128, IntPtr.Zero);
if (error == 0)

return true;
else return false;

}

//public bool Record()
//{
// error = mciSendString("set recsound bitspersample 16", null, 0, IntPtr.Zero);
// error = mciSendString("set recsound samplespersec 44100", null, 0, IntPtr.Zero);
// Pcommand = "record recsound";
// error = mciSendString(Pcommand, null, 128, IntPtr.Zero);
// if(error==0)

// return true;
// else return false;

//}
public bool ResumeRecord()
{

Pcommand = "record sounddev";
error = mciSendString(Pcommand, null, 128, IntPtr.Zero);
if (error == 0)
return true;
else
return false;

}
#endregion

#region Status

public bool IsPlaying()
{
Pcommand = "status sounddev mode";
error = mciSendString(Pcommand, returnData, 128, IntPtr.Zero);
if ((returnData.Length >0) && (returnData.ToString().Contains( "playing")))

return true;

else
return false;
}

public bool IsRecording()
{
Pcommand = "status sounddev mode";
error = mciSendString(Pcommand, returnData, 128, IntPtr.Zero);

if (returnData.Length > 7 && (returnData.ToString().Contains("recording")))
return true;
else
return false;
}

public bool IsOpen()
{
Pcommand = "status sounddev mode";
error = mciSendString(Pcommand, returnData, 128, IntPtr.Zero);
if (returnData.Length == 4 && returnData.ToString().Substring(0, 4) == "open")
return true;
else
return false;
}

public bool IsPaused()
{
Pcommand = "status sounddev mode";
error = mciSendString(Pcommand, returnData, 128, IntPtr.Zero);
if (returnData.Length == 6 && returnData.ToString().Substring(0, 6) == "paused")
return true;
else
return false;
}

public bool IsStopped()
{
Pcommand = "status sounddev mode";
error = mciSendString(Pcommand, returnData, 128, IntPtr.Zero);
if (returnData.Length == 7 && returnData.ToString().Substring(0, 7) == "stopped")
return true;
else
return false;
}
#endregion

#region Logic
public void GetRecPosition()
{
Pcommand = "set playmsound time format samples";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
Pcommand = "play playmsound";
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
StringBuilder retStr = new StringBuilder(1000);
string sCommand = "status playmsound position ";
mciSendString(sCommand, retStr, 1000, IntPtr.Zero);
}

public int GetCurentMilisecond()
{
Pcommand = "status sounddev position";
error = mciSendString(Pcommand, returnData, returnData.Capacity, IntPtr.Zero);
if (returnData.ToString() != "")
return int.Parse(returnData.ToString());
else
return 0;
}

public int GetLength()
{
Pcommand = "Set sounddev time format milliseconds";
error = mciSendString(Pcommand, returnData, returnData.Capacity, IntPtr.Zero);
Pcommand = "status sounddev length";
error = mciSendString(Pcommand, returnData, returnData.Capacity, IntPtr.Zero);
int length;
int.TryParse(returnData.ToString(),out length);
if(returnData.Length!=0)
{

return length;
}
return 0;

}
//public int GetCurentMilisecond()
//{
// Pcommand = "status sounddev position";
// error = mciSendString(Pcommand, returnData, returnData.Capacity, IntPtr.Zero);
// return int.Parse(returnData.ToString());
//}

public void SetPosition(int miliseconds)
{
if (IsPlaying())
{
Pcommand = "play sounddev from " + miliseconds.ToString();
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
}
else
{
Pcommand = "seek sounddev to " + miliseconds.ToString();
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
}
}

public int GetSongLenght()
{
if (IsPlaying())
{
Pcommand = "status sounddev length";
error = mciSendString(Pcommand, returnData, returnData.Capacity, IntPtr.Zero);
return int.Parse(returnData.ToString());
}
else
return 0;
}

#endregion

#region AudioVolume
public bool SetVolume(int volume)
{
if (volume >= 0 && volume <= 1000)
{

Pcommand = "setaudio sounddev volume to " + volume.ToString();

// Pcommand = "set sounddev volume to " + volume.ToString();
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
return true;
}
else
return false;
}

public bool SetBalance(int balance)
{
if (balance >= 0 && balance <= 1000)
{
Pcommand = "set sounddev left volume to " + (1000 - balance).ToString();
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
Pcommand = "set sounddev right volume to " + balance.ToString();
error = mciSendString(Pcommand, null, 0, IntPtr.Zero);
return true;
}
else
return false;
}

#endregion

}
}

TimerClass for Android C# style

Here is an example re-usable timer code. You just need to write your code in the Run Methods
This will be easy for those who are migrating from C#

class EBTimerTask extends TimerTask
{
Activity _parent;

public void SetParent(Activity parent)
{
_parent = (Activity) parent;

}

@Override
public void run()
{
//Write your code to execute in timer thread here
//Blah ...blah..blah..

//If you application need to update UI elements write those conde in the
//Timer action run method
EBTimerAction timerAction = new EBTimerAction();
timerAction.SetParent(_parent);
_parent.runOnUiThread(timerAction);
}
}

class EBTimerAction implements Runnable
{
Activity _parent;
Drawable _curImage;

public void SetParent(Activity parent)
{
_parent = (Activity) parent;

}

@Override
public void run()
{
//Safe to update UI elements from here
//Collect UI element pointers by using findViewById and use it here
}
}


Call it like this from your Activity Class

EBTimerTask task = new EBTimerTask();
task.SetParent(this);

timer1 = new Timer();
timer1.schedule(task, 0, 50);

MessageBox for Android

I switched to android from C# world. I have a tendency to program it like C# as I think it is fairly more readable than the way they use braces in Java. Here is a static class which you can easily use in you application to display a message box. I just tried to follow the simple MessageBox syntax we have in C#. You may need to pass the "this" pointer of your Activity . (Activity is kind of an Android version of Form or Dialog)

class EBMessageBox
{

static void ShowMessage(String text, Activity parent)
{
final AlertDialog alertDialog = new AlertDialog.Builder(parent)
.create();
alertDialog.setTitle("Wran");
alertDialog.setMessage(text);

alertDialog.setButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{

alertDialog.cancel();

}
});
alertDialog.show();
}

}