Friday, May 2, 2014

Android Package Name From APK Java Code Sample

apk-icon
public String getPackageNameByAPK(String _strAPKPath, Context _activityORservice)

Java Source Code
The Java language source code with android.content.pm.PackageManager to get the package name from a .apk file is shown in this post for online learning purposes.

Android apps are supplied in .apk files(even if you download from the Play store) which contain all information needed to install an app on an Android smartphone.
Once an app is installed on the phone it is identified by a unique package name; the package name format is:

  1. com.usrax.ca
  2. com.honestitconsultancy.patric
  3. mysymphony.pmi.com


This value is taken from the Manifest.xml file which is already present inside the .apk file of an Android application(app).

If we search "get package name from .apk" on Google we won't be able to find the source code to do this on the first page; almost everyone tries to tell us that this will be done through the command line.

This post will answer the following question:
Android, get the package name from apk file in your program

Package Archive files

There is a little twist behind these search results, is there another name for .apk files?
Yes sir, the full name of .apk files is "Package Archive". You can say that's the legal name .apk is only a nickname used by the Linux OS (Android is a Linux) and developer community.

Thursday, February 6, 2014

GROUP BY Date Time, Day, Month, Year, calculate SUM function in SQLite for app developers


SELECT strftime('%m', trxDateTime) as valMonth, 
SUM(trxAmount) as valTotalMonth 
FROM trx_log 
WHERE strftime('%Y', trxDateTime)='2014' GROUP BY valMonth

Given above is the query, which will be explained in the blog below; continue reading for further details.

SQLite GROUP BY Day, Month, Year and sum query example

I have a database table that contains a few fields like transaction date, which is a string representing date time, transaction amount, and transaction status in an SQLite database present on an Android device. The SQL Lite database contains a table named "trx_log" The table has fields _id int, trxDateTime text, trxTargetNumber text, trxAmount number, and trxStatus text. A graphical representation of the table structure is given below:

sqlite-android-search-by-year-group-by-month

SQLite Table used in the example of GROUP BY date, time, month, year, and SUM function.

SQLite Query Sum and Group By Year

How to calculate the sum of all transactions that took place in 2014? What is the SQLite query for the group by results by year and calculating a sum? We will combine SQLite aggregate function SUM with GROUP BY Clause.

SELECT strftime('%Y', trxDateTime) as valYear, SUM(trxAmount) 
FROM trx_log WHERE valYear = '2014' GROUP BY valYear

Wednesday, September 4, 2013

Android MediaRecorder.setMaxFileSize Exception due to file size

Android Media Recorder will stop functioning and show a Java.lang.RuntimeException if we provide a very small file size, for example if you will put 1024 as the MediaRecorder.setMaxFileSize parameter, the recording won't even start in the first place. Remember, the number provided as input to this method represents maximum number of bytes which would be stored in a file by the MediaRecorder.
Android MediaRecorder

The reason is that it takes almost 10 KB to store a audio recording of 1 second or so. When you will put 1024 bytes as a parameter, the MediaRecord will simple run out of space when it will try to stop the voice recording upon reaching the tiny number 1024 bytes. The error code returned by such a situation is -22, and the logging line will look something like the one given below:

Wednesday, March 20, 2013

Determining percentage of colors in a bitmap using C# without getPixel

To keep things simple, let's suppose we have a black and white bitmap image.
I will not use getPixel method here, Bitmap.getPixel() is a very expensive method, and it alone can turn your program into a lazy snail.

Please note that I am using a Format24bpprgb image format here, 24BPPRGB can be defined as:
Each pixel in the image is represented by 24 bits. First 8 bits represent red color, next 8 bits represent green color, and last 8 bits represent blue color in a bitmap.

Another popular format is 32BPPARGB, in this format the first 8 bits represent "Alpha" or the opacity of pixel, next 3 bytes or 24 bits describe the RGB components same like 24BPPRGB.

Given below is the C# language source code for checking pixel colors without Bitmap.getPixel() method.

Friday, November 11, 2011

What makes Android Programming Simpler and iOS difficult?

ios-5-android-ice-cream-sandwich-apple-google

I cannot start writing iPhone and iPad software because?

I don't have an Apple... No! don't bring me a KG of fresh red apples please, I am referring to the Apple which is a computer. It's impossible to code stuff up without an Apple machine, even for sake of learning. Apple MUST create a tool chain for people running Windows as we know it's the most widely used operating system, just like the iPhone which is a crazily used "Somewhat Smart" Phone. They could create a development environment, and a few emulators to get new going with iOS development. I believe it would cost less than $100k to develop such a solution, maintenance cost won't go beyond this as well.