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 an .apk file is shown in this post for online learning purposes.

Android apps are supplied in .apk files(even if you download from Play store) which contain all information needed to install an app to an Android smart phone.
Once an app is installed on a 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 command line.

This post will answer the following question:
Android, get 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 nick name used by the Linux OS (Android is a Linux) and developer community.



It is possible to retrieve various nuggets of information Android package archive or .apk files using Android PackageManager class programatically in Java language.

The class android.content.pm.PackageManager will return the information about your package (or .apk) in a android.content.pm.PackageInfo object.










Java Source Code Example

The Java programming language source code to get the package name from an .apk file is given below.
I have created a convenience method for you which you can utilize in your Java app code easily.


public String getPackageNameByAPK(String _strAPKPath, Context _activityORservice){
 String strRetVal = "";
 PackageManager packMan = null;
 PackageInfo packInfo = null;

  try{

  if(_strAPKPath == null) return "";

  Log.d(K.ATAG, "getPackageNameByAPK(): " + _strAPKPath);
  if(_activityORservice == null) {
   Log.e(K.ATAG, "Context is null");
    return "";   
  }

 packMan = _activityORservice.getPackageManager();  
 packInfo = packMan.getPackageArchiveInfo(_strAPKPath, 0);
 strRetVal = packInfo.packageName;
   
 }catch(Exception e){
  Log.e(K.ATAG, e.toString() + "" );
 }

  Log.d(K.ATAG, "RetVal: " + strRetVal);
 return strRetVal;
}//Beautify code with tohtml.com/java


Note, this is actually WORKING CODE, copied straight from one of my already deployed apps.
All you need is some common sense and a mug of coffee before performing the magical copy/paste operation.

An instance of the Package Manager can be acquired by calling getPackageManager() method of android.content.Context class, which actually represents the activity or service from which you are making the method call.

The details about PackageManager and the method getPackageArchiveInfo can be found on the URL given below:
http://developer.android.com/reference/android/content/pm/PackageManager.html




172 comments:

  1. Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

      Delete
  2. Did you ever think is it possible to edit an APK file or change the way it works?
    http://goo.gl/rv6JRT

    ReplyDelete
  3. Abdul Sattar, yes it is possible to "unpack" an APK and extract its code, modify it and re-package it again.

    Check this link:
    https://code.google.com/p/smali/

    The changes are done in smali language which is really complicated, it is made so on purpose to make reverse engineering difficult. I tried to do it on behalf of a freelance client once, but we didn't make much progress so the project was ended after a week or so.

    ReplyDelete
  4. Hy author,
    I am founder of game killer
    I like your article THANKS FOR SHARING

    ReplyDelete
  5. This is really a great Post. Thank you for sharing this very nice post awesome keep sharing.
    Z4Root Rooting Software

    ReplyDelete
  6. Great Sharing I Like your article.Its too much good.
    I Suggest you Happy Fathers Day Wishes/Greedings 2018 Please Review and Give FeedBack

    ReplyDelete
  7. NiCe Sharing.Great Article . I like it....! Its too much great article Check Online All the Punjab Boards 10th Class Result 2018

    ReplyDelete
  8. The out call and in call services of the Vadodara Escorts Services are absolutely popular among their clients and each one of them is said to be absolutely professional in this matter.
    Vadodara Escorts Services

    ReplyDelete
  9. Read Online Books And Online Results
    Read Online Books And Online Results

    Read Online Books Online Library for Urdu Novels Famous Urdu Novels, Download PDF Urdu Novels. booksresult.com

    Board of Intermediate & Secondary Education Results from all Pakistani boards prize bond draw

    list Prize Bond results.

    Read Online Books
    Read Online Digest
    Read Online Novels

    Read Online Books And Online Results https://booksresult.com

     

    ReplyDelete
  10. Read Online Books And Online Results
    Read Online Books And Online Results

    Read Online Books Online Library for Urdu Novels Famous Urdu Novels, Download PDF Urdu Novels.booksresult.com Board of Intermediate & Secondary Education Results from all Pakistani boards prize bond draw list Prize Bond results.

    Read Online Books
    Read Online Digest
    Read Online Novels

    Read Online Books And Online Results https://booksresult.com

     

     
    Aanchal Digest August 2018 Free Download

    ReplyDelete
  11. get apk
    GetAPK Market Download Free For Android, Play Store alternative to download free apps using GetAPK Market. Now download unlimited apps for free.

    ReplyDelete
  12. Its giving a good info about lottery and Toursim place in karanataka
    http://www.keralalotteryresults.live/
    http://www.arsikere.live/
    http://sattakingmatka.org/
    www.keralalotteryresults.live
    www.arsikere.live
    www.sattakingmatka.org

    ReplyDelete
  13. Its giving a good info about lottery and Toursim place in karanataka
    http://www.keralalotteryresults.live/
    http://www.arsikere.live/
    http://sattakingmatka.org/
    www.keralalotteryresults.live
    www.arsikere.live
    www.sattakingmatka.org

    ReplyDelete
  14. Very nice post. I just stumbled upon your weblog and wished to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again very soon!
    please check this link

    ReplyDelete
  15. To get nice apps and games, download Blackmart as it has got some of the best apps in every category.

    ReplyDelete
  16. Hi to all, the contents present at this website are truly awesome for people experience, well, keep up the good work fellows.VTU Notes

    ReplyDelete
  17. This post is connected with what I'm concerned with and its phenomenally made. Much appreciated a whole lot for your dedicated...
    click here

    ReplyDelete
  18. best one I always do it for my knowledge

    ReplyDelete
  19. Packing manager of android is a great tool for android users. You can similarly use this website for android apps.
    unlockmytv apk

    ReplyDelete
  20. Satta Maharaj providing all Satta King results such as Sattamaharaj 2021, Gali, Desawar, Faridabad, Ghaziabad results superfast, we trust in offering fast and accurate Satta Maharaj results in 2021

    Satta Maharaj
    www.sattamaharaj.com

    ReplyDelete
  21. At first I thought this blog was not interesting but after I saw the contents it really impressed me Gps pelacak mobil


    ReplyDelete
  22. I've never come across a blog as good as this and it's highly recommend blog megawin slot

    ReplyDelete
  23. There are blogs as good as this and no block can be trusted other than this marketing digital

    ReplyDelete
  24. just this time I found a blog that is as good and cool as this blog slot77

    ReplyDelete
  25. all the blogs that I have read this time I see a blog as good as this slot gacor

    ReplyDelete
  26. From the blogs that I have read, only this blog adds to my knowledge the most distributor pulsa

    ReplyDelete
  27. Nice blog !! the issuue that you touch is very informative and great. Keep it up. we are waiting for more apk reviews.
    Must watch this

    ReplyDelete
  28. Thank you very much for upadate very informative blog. Hope you upload more these kin of blogs. Thanks.
    Visit here

    ReplyDelete
  29. the website design is very good and the information on this website looks also good

    Castle Clash MOD APK
    Castle Crush MOD APK

    ReplyDelete
  30. A great degree energizing article thanks for sharing it to each one of us. Looking forward to more information and you have continually intrigued me.
    Best Info

    ReplyDelete
  31. I know your post give me the great information. I am totally impressed with your article and must want to say your posting style is different then others. I am really very thankful to you.
    Best Review

    ReplyDelete
  32. This is a great tribute. Thanks for posting it
    cuan777 situs slot pulsa tanpa potongan
    cuan777 agen Pay4D resmi dan terpercaya

    ReplyDelete
  33. Great site! I really love the way it is simple on my eyes. I am thinking about how I may be told at whatever point another post has been made.
    click Here

    ReplyDelete
  34. one of the many blogs that are very good and understandable and highly recommended pulsa murah

    ReplyDelete
  35. This blog is very complete and very high quality and very easy to understand Paket CCTV

    ReplyDelete
  36. Gebyar123 adalah situs game online yang terbaik dan terpercaya yang terbukti mudah menang.

    ReplyDelete
  37. Situs judi dan slot online terbaik dan terpercaya
    <a href="https://163.47.11.90/%22%3EMonas77</a>

    ReplyDelete
  38. Situs judi dan slot online terbaik dan terpercaya
    https://163.47.11.90/

    ReplyDelete
  39. I really liked reading your post! Very high quality content and useful information similar to my post on places to visit to With such a valuable website I believe you deserve to be ranking even higher in the search engines.

    click Here

    ReplyDelete
  40. Your posts are really inspiring and useful. I think you deserve better attention on Google search rankings.
    visit here Please

    ReplyDelete
  41. Thanks for this post and this post is very informative post for me and i have bookmarked this post as i can read it everyday for you and i hope everyone is going to read this post and it can go viral on social media.
    Click it

    ReplyDelete
  42. This site have particular software articles which emits an impression of being a significant and significant for you individual, able software installation.This is the spot you can get helps for any software installation, usage and cracked.
    Must See It

    ReplyDelete
  43. This comment has been removed by the author.

    ReplyDelete
  44. Chơi đá gà trực tuyến mới nhất hiện tại được cập nhật liên tục tại nhà cái uy tín vegas79, tại đây có khá nhiều khuyến mãi và nhiều giải thưởng lớn nhỏ khác nhau
    Da ga truc tuyen

    Da ga cua dao

    Da ga Vegas79

    Đá gà cựa sắt

    ReplyDelete
  45. Tỷ lệ kèo nhà cái Ma cao là địa chỉ cá cược uy tín hàng đầu giữa thị trường nhà cái đầy sôi động. Truy cập ngay vào trang tỷ lệ kèo nhà cái Macao, người chơi thỏa sức đam mê với nhiều hình thức chơi khác nhau. Cùng tìm hiểu xem vì sao nhà cái Macao lại giàu sức hút như vậy.
    Ty le ma cau
    Keonhacai K8
    Ty le ca cuoc
    Bet69
    Keonhacai
    Keo Malaysia
    W88 club

    ReplyDelete
  46. เว็บ naza easy to play, get real money

    ReplyDelete
  47. คาสิโนออนไลน์ Available 24 hours a day, no matter where you are, you can play games anytime, anywhere. Just add Line @123MAXX

    ReplyDelete
  48. ag gaming Sign up for free!! Deposit - withdraw, no minimum

    ReplyDelete
  49. เว็บคาสิโน No.1, Play in all formats like a real club. no matter where you are can play at any time. full service.

    ReplyDelete
  50. เว็บ123 Casino website, online games, the best football betting website.

    ReplyDelete
  51. คาสิโน123 Make a very simple income just fingertips.

    ReplyDelete
  52. ซื้อหวยหุ้น We provide best services to all class of clients.

    ReplyDelete
  53. เว็บนาซ่า The best online football betting Click Now

    ReplyDelete
  54. abcbet Best Casino Sites Click Now

    ReplyDelete
  55. เว็บ 168 Betting on online is the best answer for the gambler.

    ReplyDelete
  56. เว็บนาซ่า Sign up for free!! Deposit - withdraw, no minimum

    ReplyDelete
  57. nazago easy to play, get real money

    ReplyDelete
  58. maria The number 1 best website to make Money

    ReplyDelete
  59. เว็บ168 The number 1 best website to make Money

    ReplyDelete
  60. Gebyar123 adalah situs betting online terbaik dan terpercaya yang terbukti mudah menang.

    ReplyDelete
  61. ยอดเทิร์นโอเวอร์ Betting amount of objective Have fun and enjoy playing games without limits. Complete the total number of play to complete the goals set.

    ReplyDelete
  62. naza Sign up for free!! Deposit - withdraw, no minimum

    ReplyDelete
  63. maria168 The number 1 best website to make Money.

    ReplyDelete
  64. ทางเข้า 123 If you are one who likes and is interested in playing online games, then you should not miss the site. Entrance play online games the best right now.

    ReplyDelete
  65. ไพ่แคงออนไลน์ Card games have a playing system that is fun and easy to understand. Show the cards and compare the scores to finish the game.

    ReplyDelete
  66. ราคาบอล The deities didn't know what to do with the two people who prayed for the angels, so they just sat there pretending not to know.

    ReplyDelete
  67. 619คาสิโน The best casinos in Thailand make good money

    ReplyDelete
  68. ดูหนังออนไลน์ Website to watch movies online for free. watch movies on mobile slip without interruption.

    ReplyDelete
  69. wwbet website online the best in the worlds.

    ReplyDelete
  70. maria website online the best in the worlds.

    ReplyDelete
  71. 123 casino Casino websites that have to try once and then you will know that making money is very easy.

    ReplyDelete
  72. บาคาร่า123 Bacara online is easy to play at your fingertips. received a lot of wealth.

    ReplyDelete
  73. เว็บหวยสามารถ website that have all the betting in it to answer all the needed

    ReplyDelete
  74. สูตรหวยยี่กี Online gambling website that allows you to make great money And also allows you to bet 24 hours.

    ReplyDelete
  75. เกม 123 best online gambling games Click Now

    ReplyDelete
  76. สล็อตเว็บตรง If anyone is looking for a game that is easy to crack, try Guardians of Ice & Fire slot, a slot game from PG camp. Ice and Fire director slot game. Web slot games straight from PG Slot camp come to our website. There are all PG slot games in addition to that. We include all slots game camps. come into one of our websites Includes all slots games in one website. For you to enjoy with more than 500 slots games from all camps on our website. and we also have a system Trial Slots Allows you to try different slot games of all camps for decision making. before placing a bet with real money Try to play slots for free, get real money, try to play for free, no need to top up. No registration required, if you are interested, try playing slots easily.

    ReplyDelete
  77. wwbet Online lottery website that gives full price best price in Thailand need this website only.

    ReplyDelete
  78. allbet Collecting the most popular online games into one website, You can feel the mosphere in a real club. International Service Standards.

    ReplyDelete
  79. 123 slot Lots of games, including many online slots betting games. Automatic deposit-withdrawal, fast service.

    ReplyDelete
  80. ap123 slot casino online gambling A collection of the hottest games right now. guarantee of stability Safety for all customers.

    ReplyDelete
  81. สล็อตแตกง่าย Online gambling website, direct website, what will be the best is a direct website without cheating sent directly, not through an agent from abroad But it's you will be able to bet Those websites are good because the things you will find are the ones that are not of good quality. Cheating capital bets and frequent lag games Which at this point is not a good thing at all. for gamblers to have to bet Rix789

    ReplyDelete
  82. วิธีดูราคาบอล Present daily price and the next day before the start of that match You can check quickly through the application.

    ReplyDelete
  83. เว็บหวยสามารถ Online lottery website that gives full price best price in Thailand need this website only.

    ReplyDelete
  84. Recommend the best gambling website in them, this is really easy to play123over

    ReplyDelete
  85. ดูหวยหุ้น looking around some webs, seems a pretty nice platform you are using.

    ReplyDelete
  86. Maria168 Easy to make money good to services.

    ReplyDelete
  87. 1688 Easy to make money good to services.

    ReplyDelete
  88. I am thankful to you for sharing this plethora of useful information. I found this resource utmost beneficial for me. Thanks a lot for hard work.เปิดยูสคาสิโนพร้อมโปร

    ReplyDelete
  89. สูตรบาคาร่า sa gaming Welcome everyone, good service, easy to use. Fun games make a lot of money. one website complete.

    ReplyDelete
  90. Maria168 Easy to make money good to services.

    ReplyDelete
  91. เว็บคาสิโนออนไลน์อันดับ1 No. 1 online gaming website We have a system to refer friends that can make money easily. You can press copy link. and forward to your friends to play easily.

    ReplyDelete

Feel free to talk back...