Determine if Android apps are installed, running

Source: Internet
Author: User
<span id="Label3"></p><p><p></p></p><p>This article describes 3 ways to determine if an app is installed on your phone, whether the app is running, and gets the installation intent of an APK file on your PHONE. launch the intent to install the APK directly.<br> <br>/**<br>* Determine if the app is installed<br>*<br>* @param context<br>* @param packagename<br>* @return<br>*/<br>Private Boolean isInstalled (context context, String Packagename) {<br>Boolean hasinstalled = false;<br>Packagemanager pm = Context.getpackagemanager ();<br>List<packageinfo> list = PM<br>. getinstalledpackages (packagemanager.permission_granted);<br>For (packageinfo P:list) {<br>If (packagename! = null && packagename.equals (p.packagename)) {<br>hasinstalled = true;<br>Break<br>}<br>}<br>Return hasinstalled;<br>}<br> <br>/**<br>* Get intent of File installation<br>*<br>* @param file<br>* @return<br>*/<br>Private Intent getfileintent (file File) {<br>Uri uri = Uri.fromfile (file);<br>String type = "application/vnd.android.package-archive";<br>Intent Intent = new Intent ("android.intent.action.VIEW");<br>Intent.addcategory ("android.intent.category.DEFAULT");<br>Intent.addflags (intent.flag_activity_new_task);<br>Intent.setdataandtype (uri, type);<br>Return intent;<br>}<br> <br>/**<br>* Determine if the app is running<br>*<br>* @param context<br>* @param packagename<br>* @return<br>*/<br>Private Boolean isrunning (context context, String Packagename) {<br>Activitymanager am = (activitymanager) context<br>. Getsystemservice (context.activity_service);<br>list<runningappprocessinfo> list = am.getrunningappprocesses ();<br>For (runningappprocessinfo Appprocess:list) {<br>String ProcessName = appprocess.processname;<br>If (processName! = null && processname.equals (packagename)) {<br>Return true;<br>}<br>}<br>Return false;<br>}</p><p><p>Determine if Android apps are installed, running</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.