Tag Archives: android

How to Generate a PDF in Xamarin Android

It may sound simple, but when it comes to Xamarin, all the problems starts to emerge. So basically Xamarin does not provide any special class for PDF generation.

Failed Solution 1
So we were let alone to use the Android PDFDocument class. Which Unlike in the Native Android did not work. Actually it was giving me a White and blank document. When searching for the Xamarin Documentation what I found was the Xamarin documentation having the Android Reference Code which is very disappointing (Link to Documentation)

Here is the Code snippet for it(I may have made a mistake here, let me know if you guys found a solution for using PDFDocument class )

private String sdCardPathforPDF;
private String filePath;
private FileStream stream;

sdCardPathforPDF = Environment.ExternalStorageDirectory.AbsolutePath;
filePath = Path.Combine(sdCardPathforPDF, "MyPDF/test5.pdf");
stream = new FileStream(filePath, FileMode.Create);

tView = new TextView(context);
tView.SetTextColor(Color.ParseColor(resource.GetString(Resource.Color.black)));
tView.Text = "Hello";
tView.SetHeight(50);
tView.SetWidth(50);

var document = new PdfDocument();
var pageInfo = new PdfDocument.PageInfo.Builder(612, 792, 1).Create();

var page = document.StartPage(pageInfo);
tView.Draw(page.Canvas);
document.FinishPage(page);

document.WriteTo(stream);

stream.Close();
document.Close();

Toast.MakeText(context, "PDF Generated", ToastLength.Short).Show();

Failed Solution 2
Then I searched for a plugin or a 3rd party library, ohhh my god, I found some expensive plugins

Capture

Who would love to buy a plugin for 1600 usd??? Apitron and XFINIUM are some of them

Failed Solution 3
I found some Free open source libraries for Android, so I thought of  Java Bind it, but when i tried to Java Bind them, but I ended up getting lots of errors that i cannot fix it unless I am the developer of that library. So I dropped that Idea as well.

Failed Solution 4
Then after the disappointment of JavaBind, I came across an article saying that the iText library has been published for .Net in the name of iTextSharp. But when I added that Nuget Package I came across an error saying that

System.IO.FileNotFoundException: Could not load assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?

so It says there is an assembly called System.Drawing dll is missing. I tried to manually add it but it did not work. When I researched on it, it said that Mono for Android(Xamarin Android Framework) does not include that ‘dll’ I dont know how come a popular ‘dll’ got missed out of their framework.

At last a solution that Worked
So with all of the frustration I had, I did not give up on finding a solution till i came across problem where a guy has used ‘iTextSharp’ in Xamarin Android and its working. But he did not mention or reply my question in that thread. So I thought of giving a final look at the Nuget Manager. This time just like the previous time I searched for ‘iTextSharp’ but this time I went through each and every result the list showed.
And Hoooray I found It the one I am searching for, some one has made a nuget of ‘iTextSharp’ for Xamarin, its called “Xam.iTextSharpLGPL”

XamiTextSharp

And this worked like a Magic. And this library has more functionality than the default PDFDocument.
This library is based on iTextSharp 4.1.6  which means licensed under LGPL. Free to use and it is an Open source library.
Open source project can be found in Bit Bucket : https://bitbucket.org/smarongiu/xam.itextsharplgpl

So this is the Basic code of Writing a Simple PDF Doc

System.IO.FileStream fs = new FileStream(Server.MapPath("pdf") + "\\" + "First PDF document.pdf", FileMode.Create)

// Create an instance of the document class which represents the PDF document itself.
Document document = new Document(PageSize.A4, 25, 25, 30, 30);
// Create an instance to the PDF file by creating an instance of the PDF Writer class, using the document and the filestrem in the constructor.

PdfWriter writer = PdfWriter.GetInstance(document, fs);

Before we can write to the document, we need to open it.

// Open the document to enable you to write to the document

document.Open();

// Add a simple and well known phrase to the document in a flow layout manner

document.Add(new Paragraph("Hello World!"));

// Close the document

document.Close();
// Close the writer instance

writer.Close();
// Always close open file handles explicitly
fs.Close();

I grabbed this quick code snippet from Micke Blomquist

Hope this article will help people like me in future…!
See ya…!

Advertisements

Android Proguard a General Idea

What is Proguard on android and what does it do?

ProGuard is a tool that comes with the Android SDK. It  shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized .apk file that is more difficult to reverse engineer. Because ProGuard makes your application harder to reverse engineer, it is important that you use it when your application utilizes features that are sensitive to security.

How to enable it? And is it recommended?

ProGuard is integrated into the Android build system. And to enable it you just have to find the “project.properties” file in your android project and have to uncomment the line which sets the path for the ProGuard. Also Proguard slows the app building sequence.
So you do not have to invoke it manually. ProGuard runs only when you build your application in release mode, so you do not have to wait longer time when debugging the app. Having ProGuard run is completely optional, but highly recommended.

So is that all that we have to do to enable and use ProGuard?

Yes that’s the basic, and it only does the Shrinking, but there are 2 more functions that give more advantages in increasing the security and management of the build.
They are Obfuscation and Repackaging.

So what is Obfuscation and how does it Work

With tools available to extract the contents of APK’s, deodex, and read the class files, it’s important to obfuscate to protect the proprietary aspects of your codebase.

ProGuard generates a mapping file that allows you to map the stack traces of obfuscated code to actual methods. Basically it replaces the methods in meaning full name to something unguessable like a work or letter.

Original Code

public Data(int id, int result, String message) {
       mId = id;
       mResult = result;
       mMessage = message;
    }

Obfuscated Code

public a(int paramInt1, int paramInt2, String paramString)
    {
       this.a = paramInt1;
       this.b = paramInt2;
       this.c = paramString;
   }

 Hope you got an idea on how it works

So what is Repackaging?

Repackaging allows ProGuard to take externals jars and class files and move them to a single container with a common java package location.

For those of you building libraries, repackaging is extremely helpful if you choose to show a simple interface to third party developers while keeping a maintainable and well structured project hierarchy in the source repository. This can also be useful in organizing lower level packages while exposing well defined interfaces!

 Optimizing

There is another function of Proguard which Optimizes the code, where you can specify which part of the code, which type of code needs to be Optimized.  However, there are known incompatibility issues with various Dalvik versions.
But It is good to know this feature, which can be used without issues using some other tools.

Reference : http://www.crashlytics.com/blog/mastering-proguard-for-building-lightweight-android-code/, http://developer.android.com/tools/help/proguard.html

Last Runner – Android, iOS and Windows Phone Game

android game

Last Runner is an Endless runner made for Android and iOS. Unlike Temple run and Subway Surfers, it’s a 2D game similar to Monster Dash by Half Brick studio.

Screenshot_2015-02-05-11-08-17  volcano forest

It got only one function, and that is to tap the screen for jump and double tap the screen for double jump. The Double jump functionality is a bit Tricky, it Does not always double jump when you try to double jump. It some times frustrates the player, but that is the beauty of an Addictive game.

Developer says that
“The One who Masters the Double Jump will conquer this Game”

Another most wonderful and main feature is all the drawings of this game are hand drawn and the scene changes every time you surpass a certain score.

Also the Game is integrated with Google Play Services so the player can log with Google Plus and  compete with their friends and Earn Achievements through the Game.

Google Play Game services feature is only available in the Android version

gplay
The Game starts with a Story where a Volcano is erupting in a beautiful environment, its the first sign of world coming to an end. The two characters, the Professor and the Hero are discussing about collecting Life energy from around the world to create a magical Serum which will help turn a bare planet into another beautiful Earth which the earthlings are planning to migrate. So the hero turns into his Super Mode to Go after them through different environments lands.
last runner Winter Scene last runner

last runner high score
The game is a super good casual one specially when u are waiting for a train or bus. Competing with your friends makes it more Addictive. This is a Must try Game.

Watch the Trailer here

So Go On Guys, Download the Game and start playing
DON’T FORGET to RATE  🙂

You can download it by clicking the Buttons below
google_play_store_icon lat runner ios  last runner windows phone

Whatsapp Web – Desktop App Workaround

Hi guys, its cool to see whatsapp coming to the desktop, at least as a chrome app.
But I know there are a lot of people who use browsers other than Google Chrome, and the people who actually wants a hassle free separate desktop app, rather than opening a browser and going to the specific site to view the messages.

So here I am gona explain how to create a chrome application which, kind of create a dedicated browser app for you which you can place in your browser or task bar just like another app and when you click on it, it directly opens like another desktop app.

Step 1
So to do that first you need a Google Chrome browser. If u are a Google Chrome hater, please don’t worry, it only for the first time, after that you can forget about it . Use this link to download the Google Chrome

Step 2
Open the Google Chrome and get in to the Whatsapp web app, using this link https://web.whatsapp.com/

Step 3
Open your Android Whatsapp app and on the menu select the Whats app Web.
Screenshot_2015-01-26-10-28-42
Scan the QR code in the website you visited now using the QR scanner just opened in the Whatsapp android app. And you have successfully registered and accessed the chat.

Step 4
Now in the google Chrome Menu Go to
More Tools –> Create Application Shortcut
chrome

Now you will see the option to create the short cut in Taskbar Desktop or anywhere you like

app

TA DA , now you have a dedicated Whatsapp Desktop App which you can click open with a single click.

Whatsapp Desktop App

This technique can be used with all other websites as well, like facebook, twitter and many others.

Hope this article is helpful for you free feel to share with you friends
😀

VAM Browser – Award Winning Research

1

This is a Research done by me and my research group back when we were doing our final year BSc in IT. This is kind of a predecessor for the Cortona that’s available for windows phone 8.1 now

Also this research won the “Youth Encouragement Award” in
the eSwabhimani 2012 Sri Lanka

The Research Paper is Published at the GHTC SAS 2013 Conference Held at Thiruvananthapuram India

See the research Here
IEEE_logo

or Use QR Reader
vam

This is what our research stated back in 2012 states

“Technology is growing fast with the time. The days of desktop pcs and laptop pcs’ are disappearing fast. Now the latest and fastest growing technology is smart phone technology. Even though the earlier smart phones did not support much features, now it is been appearing with much more powerful hardware to support latest features. Internet access is a must these days, any smart phones without a web browser is a useless device. So, this research, Voice Active Mobil Web Browser, Assisting Vision Impaired people(VAM Web Browser), is carried out to find the difficulties Smartphone users are experiencing with their mobile web browsers and to provide a solution to it. The main research areas covered in this research project is implementing a web browser which has the feature to read web pages and to accept voice commands from user to execute some functions. Also this mobile web browser will have an advanced downloader feature which will support pausing the download and resume again. . Even though this system is not targeted to blind people the system will facilitate the vision impaired people as it got voice to text, text to voice features.”

Visit the Research Site for more details and Docs
Visit-website-button

Halloween Camera – Android App

banner

Halloween is coming closer…!
Scare your friends with the Halloween camera by taking your friend’s picture with a Ghost next to him/her

If the gallery crashes when you try to open please see the photos through your default file browser
The photos taken are inside
sdcard –> Mycamera Halloween Folder inside your memory card

Download the app here
google_play_store_icon

or use the QR Reader

qrfree.kaywa.com