すべてのActivityとServiceを取得
1303 ワード
// Activity
public void getAllActivities(Context context){
try {
// : PackageName
String packageName=context.getPackageName();
// : PackageManager
PackageManager packageManager=context.getPackageManager();
// : PackageInfo
PackageInfo packageInfo=packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
// : ActivityInfo[]
ActivityInfo[] activityInfoList = packageInfo.activities;
// : Activity
for (ActivityInfo activityInfo : activityInfoList) {
System.out.println(""+activityInfo.name);
}
} catch (Exception e) {
// TODO: handle exception
}
}
// Service
private void getAllServices(Context context){
try {
// : PackageName
String packageName = context.getPackageName();
// : PackageManager
PackageManager packageManager = context.getPackageManager();
// : PackageInfo
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SERVICES);
// : ServiceInfo[]
ServiceInfo[] serviceInfoList = packageInfo.services;
// : service
for (ServiceInfo serviceInfo : serviceInfoList) {
System.out.println("-------> " + serviceInfo.name);
}
} catch (Exception e) {
}
}