How to determine if a apk file is a home application
Imported Packages:
Import Android.content.Context;
Import android.content.Intent;
Import Android.content.pm.PackageParser;
Import Android.os.Bundle;
Import android.os.Environment;
Import Android.support.design.widget.FloatingActionButton;
Import Android.support.design.widget.Snackbar;
Import android.support.v7.app.AppCompatActivity;
Import Android.support.v7.widget.Toolbar;
Import Android.util.DisplayMetrics;
Import Android.util.Log;
Import Android.view.Menu;
Import Android.view.MenuItem;
Import Android.view.View;
Import Java.io.File;
Import java.util.ArrayList;
Decision function:
Boolean Ishomeapp (context context, String Dexpath) {Boolean ishomecategory = false;
Dexpath = Environment.getexternalstoragedirectory (). GetAbsolutePath () + "/testmarket.apk";
File Dexfile = new file (Dexpath);
LOG.I ("Findbug", "Dexpath =" + Dexpath);
if (!dexfile.exists ()) {//log.i ("Findbug", "file can ' t find");
}/* Packagemanager Packagemanager = Context.getpackagemanager ();
PackageInfo PackageInfo = Packagemanager.getpackagearchiveinfo (Dexpath, packagemanager.get_activities);
if (PackageInfo = = null) {LOG.I ("Findbug", "pkg = = null.");
return false;
for (Activityinfo a:packageinfo.activities) {log.i ("Findbug", a.name);
PackageInfo.
} * * Displaymetrics displaysmetrics = new Displaymetrics ();
Getwindowmanager (). Getdefaultdisplay (). Getmetrics (Displaysmetrics); Packageparser PackAgeparser = new Packageparser (Dexpath);
Packageparser.package dexpackage = Packageparser.parsepackage (Dexfile, Dexpath, displaysmetrics, 0);
final int size = DexPackage.activities.size ();
found:for (int i = 0; i < size; i++) {Packageparser.activity activity = dexPackage.activities.get (i);
arraylist<packageparser.activityintentinfo> intents = activity.intents;
Final int sizeintent = Intents.size ();
for (int j = 0; j < sizeintent; ++j) {Packageparser.activityintentinfo intentinfo = Intents.get (j);
Final int sizeactions = Intentinfo.countactions ();
Final int sizecategories = Intentinfo.countcategories ();
for (int k = 0; k < sizeactions; ++k) {for (int m = 0; m < sizecategories; ++m) { if (Intentinfo.getcategory (m). Equals (Intent.category_home)) {Ishomecategory = true;
Break found;
}}} return ishomecategory; }
Please indicate the error, reprint, pls mark the source, thank you