Prash's Blog

Insufficient Storage Space Available on Android when installing apps June 27, 2014

Filed under: Android — prazjain @ 5:39 pm

I tried quite a few things like uninstalling apps, moving apps to SD card but this error keeps coming back.
Here is what worked for me:


Open the Phone app and switch to Keypad.
Dial *#9900#
On the screen that appears, click on the button labelled "Delete dumpstate/logcat".

 

How to show message count on app icon in Android June 6, 2014

Filed under: Android — prazjain @ 9:08 pm
Tags:

I was curious about how whatsapp and facebook showed a count of unread messages or notifications on app icon in Android, and I wanted to find that out for myself.

It is explained well in the link below.


//This is for samsung touchwiz

public static void setBadge(Context context, int count) {
    String launcherClassName = getLauncherClassName(context);
    if (launcherClassName == null) {
        return;
    }
    Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
    intent.putExtra("badge_count", count);
    intent.putExtra("badge_count_package_name", context.getPackageName());
    intent.putExtra("badge_count_class_name", launcherClassName);
    context.sendBroadcast(intent);
}

public static String getLauncherClassName(Context context) {

    PackageManager pm = context.getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
    for (ResolveInfo resolveInfo : resolveInfos) {
        String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
        if (pkgName.equalsIgnoreCase(context.getPackageName())) {
            String className = resolveInfo.activityInfo.name;
            return className;
        }
    }
    return null;
}

Sony devices use a class named BadgeReciever.
Declare the com.sonyericsson.home.permission.BROADCAST_BADGE permission in your manifest file:
Broadcast an Intent to the BadgeReceiver:

Intent intent = new Intent();

intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.yourdomain.yourapp.MainActivity");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);
intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", "99");
intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.yourdomain.yourapp");

sendBroadcast(intent);

Done. Once this Intent is broadcast the launcher should show a badge on your application icon.

To remove the badge again, simply send a new broadcast, this time with SHOW_MESSAGE set to false:


intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", false);

More details in the links below

stackoverflow.com how-to-display-count-of-notifications-in-app-launcher-icon

android-notification-badge-app-icon-sony/

 

Ways to improve performance of wpf application March 10, 2014

Filed under: Uncategorized — prazjain @ 5:14 pm

Ways to improve performance of wpf application

Nice article about ways you can improve performance of your wpf application.

 

 

Visual Studio 2013 builds fine but Resharper 7 shows errors February 18, 2014

Filed under: C# — prazjain @ 9:59 am
Tags: , ,

I hit this problem while doing some massive refactoring on my VS 2013 solution. Visual studio showed build successful, but resharper had 400+ errors. This is how i resolved it:

Menu -> Tools -> Options -> Resharper -> Suspend

Delete Resharper cache -> [User]/AppData/Local/JetBrains/v7.1/SolutionCache

Menu -> Tools -> Options -> Resharper -> Resume

 

Bulk Xml Schema Generation and Xml Validation January 17, 2014

Filed under: C# — prazjain @ 3:22 pm
Tags: , ,

I got into a situation where I had 250+ xml files with business information (logic + data), and the code was reliant on it being correctly typed by another external business facing team.
I wrote this quick xml schema generator and validator for helping me in that process.

This is what I did:

1) Generate a xml schema for each of those xml files using this code below

public class MultibookXsdGenerator
{
public void Generate()
{
string xmlFilesDir = @”C:\Source\Grids”;
string outputDir = @”C:\XsdGenerator”;
string copyToDirectory = “xmls”;
string xsdDirectory = “xsds”;

if (!Directory.Exists(Path.Combine(outputDir, copyToDirectory)))
{
Directory.CreateDirectory(Path.Combine(outputDir, copyToDirectory));
}
if (!Directory.Exists(Path.Combine(outputDir, xsdDirectory)))
{
Directory.CreateDirectory(Path.Combine(outputDir, xsdDirectory));
}

string[] xamlFiles = Directory.GetFiles(xamlFilesDir, “*.xaml”);
foreach (var xamlFile in xamlFiles)
{
FileInfo fileInfo = new FileInfo(xamlFile);
FileInfo xmlFileInfo = new FileInfo(Path.Combine(outputDir, copyToDirectory, fileInfo.Name.Replace(“.xaml”, “.xml”)));
File.Copy(xamlFile, xmlFileInfo.FullName);
ProcessStartInfo oInfo = new ProcessStartInfo(Environment.ExpandEnvironmentVariables(“\”C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\x64\\xsd.exe\””), “/o:” + Path.Combine(outputDir, xsdDirectory) + ” ” + xmlFileInfo.FullName);
oInfo.UseShellExecute = false;
oInfo.ErrorDialog = false;
oInfo.CreateNoWindow = true;
oInfo.RedirectStandardOutput = true;
try
{
Process p = Process.Start(oInfo);
StreamReader oReader2 = p.StandardOutput;
string sRes = oReader2.ReadToEnd();
oReader2.Close();
// sRes now contains the output from xsd.exe
//File.Move(xmlFileInfo.FullName.Replace(“.xml”,”.xsd”),Path.Combine(outputDir,xsdDirectory));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}

2) Start to manually merge those xsd files to one single xsd. This is basically go to each

3) Validate the all the xml files with the main schema using the code below.

public class Validator
{
// Validation Error Count
static int ErrorsCount = 0;
// Validation Error Message
static string ErrorMessage = “”;
public static void ValidationHandler(object sender,
ValidationEventArgs args)
{
ErrorMessage = ErrorMessage + args.Message + “\r\n”;
ErrorsCount++;
}
public void Validate()
{
string dirName = @”C:\XsdGenerator\xmls”;
int fileCount = 0;
foreach (var file in Directory.GetFiles(dirName,”*.xml”))
{
fileCount++;
Console.WriteLine(“File number : ” + fileCount);
try
{
string strXMLDoc = File.ReadAllText(file);
// Declare local objects
XmlDocument xmld = new XmlDocument();
xmld.LoadXml(strXMLDoc);
xmld.Schemas.Add(null, @”./Xsds/Main.xsd”);
xmld.Validate(ValidationEventHandler);
// XML Validation succeeded
Console.WriteLine(“XML validation succeeded.\r\n”);
}
catch (Exception error)
{
// XML Validation failed
Console.WriteLine(“XML validation failed.” + “\r\n” +
“Error Message: ” + error.Message);
}

}

Console.WriteLine(“Console Messages : ” + Validator.ErrorMessage);
Console.WriteLine(“Console Error count : ” + Validator.ErrorsCount);
Console.ReadLine();
}
}

 

Compress and Uncompress in C# using .Net APIs December 3, 2012

Filed under: C# — prazjain @ 4:02 pm
Tags: , ,

Code snippet below for uncompressing a zip file to text file and compressing a text file back to zip file.
It is really minimal and I was able to uncompress 3+ gb text files using this, and as it just deals with stream you do not need to store the contents of the file in memory!
Here you go

        internal void UncompressZipFile(string fullPath, string zipPath)
        {
            //uncompress it
            Log.InfoFormat("Uncompressing XML zip file : Start");
            using (GZipStream gzs = new GZipStream(new FileStream(zipPath, FileMode.Open), CompressionMode.Decompress))
            {
                using (FileStream xmlFile = File.Create(fullPath))
                {
                    gzs.CopyTo(xmlFile);
                }
            }
            Log.InfoFormat("Uncompressing XML zip file : Finish");
        }

        internal void CompressCSVFile(string fullPath, string zipPath)
        {
            //Compress it
            Log.Info("Compressing CSV file : Start");
            using (FileStream csvFile = new FileStream(fullPath, FileMode.Open))
            {
                using (GZipStream gzs = new GZipStream(new FileStream(zipPath, FileMode.Create), CompressionMode.Compress))
                {
                    csvFile.CopyTo(gzs);
                }
            }
            Log.Info("Compressing CSV file : Finish");
        }

 

Tutorial to Setup Hadoop on Windows with Eclipse October 23, 2012

Filed under: Hadoop — prazjain @ 9:19 pm
Tags:

This is how I setup Hadoop on Windows, for anyone looking to setup Hadoop go through this : http://v-lad.org/Tutorials/Hadoop/00%20-%20Intro.html. Everything else that I tried was too complicated or had steps missing or inconsistent.

 

 
Follow

Get every new post delivered to your Inbox.