Android 的manifest解析

AndroidManifest.xml 最全详解 AndroidManifest.xml 是每个android程序中必须的文件,它位于整个项目的根目录。我们每天都在使用这个文件,往里面配置程序运行所必要的组件,权限,以及一些相关信息。但是对于这个文件,我们真正又了解多少了,还是只是停留在只会简单的配置,而不明白其中的具体含义,以及为什么要这样设置?今天就让我们来详细的学习一下这个文件里各项参数的具体含义,因为它是整个应用的入口,所以有助... 阅读详情
AI摘要

本文介绍AndroidManifest.xml文件的解析过程及关键信息。通过PackageManager、PackageInfo和ApplicationInfo类解析应用基本信息、组件信息等。深入探讨<application>标签下的配置项及其作用。

AndroidManifest.xml采用xml文件格式描述,使用xml标签的形式描述每个属性,AndroidManifest.xml的解析也遵循xml解析的规律,对AndroidManifest.xml的解析主要用到PackageManager,PackageInfo,ApplicationInfo三个类,PackageInfo描述了应用级的信息,包括应用的版本号,版本名称,对应AndroidManifest.xml最外层的信息,ApplicationInfo描述了<application></application>标签之间的信息,包括声明的meta-data和activity信息,

PackageInfo.java源码

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. /* 
  2.  * Copyright (C) 2007 The Android Open Source Project 
  3.  * 
  4.  * Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  * you may not use this file except in compliance with the License. 
  6.  * You may obtain a copy of the License at 
  7.  * 
  8.  *      http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  * Unless required by applicable law or agreed to in writing, software 
  11.  * distributed under the License is distributed on an "AS IS" BASIS, 
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  * See the License for the specific language governing permissions and 
  14.  * limitations under the License. 
  15.  */  
  16.   
  17. package android.content.pm;  
  18.   
  19. import android.os.Parcel;  
  20. import android.os.Parcelable;  
  21.   
  22. /** 
  23.  * Overall information about the contents of a package.  This corresponds 
  24.  * to all of the information collected from AndroidManifest.xml. 
  25.  */  
  26. public class PackageInfo implements Parcelable {  
  27.     /** 
  28.      * The name of this package.  From the <manifest> tag's "name" 
  29.      * attribute. 
  30.      */  
  31.     public String packageName;  
  32.   
  33.     /** 
  34.      * The version number of this package, as specified by the <manifest> 
  35.      * tag's {@link android.R.styleable#AndroidManifest_versionCode versionCode} 
  36.      * attribute. 
  37.      */  
  38.     public int versionCode;  
  39.       
  40.     /** 
  41.      * The version name of this package, as specified by the <manifest> 
  42.      * tag's {@link android.R.styleable#AndroidManifest_versionName versionName} 
  43.      * attribute. 
  44.      */  
  45.     public String versionName;  
  46.       
  47.     /** 
  48.      * The shared user ID name of this package, as specified by the <manifest> 
  49.      * tag's {@link android.R.styleable#AndroidManifest_sharedUserId sharedUserId} 
  50.      * attribute. 
  51.      */  
  52.     public String sharedUserId;  
  53.       
  54.     /** 
  55.      * The shared user ID label of this package, as specified by the <manifest> 
  56.      * tag's {@link android.R.styleable#AndroidManifest_sharedUserLabel sharedUserLabel} 
  57.      * attribute. 
  58.      */  
  59.     public int sharedUserLabel;  
  60.       
  61.     /** 
  62.      * Information collected from the <application> tag, or null if 
  63.      * there was none. 
  64.      */  
  65.     public ApplicationInfo applicationInfo;  
  66.       
  67.     /** 
  68.      * The time at which the app was first installed.  Units are as 
  69.      * per {@link System#currentTimeMillis()}. 
  70.      */  
  71.     public long firstInstallTime;  
  72.   
  73.     /** 
  74.      * The time at which the app was last updated.  Units are as 
  75.      * per {@link System#currentTimeMillis()}. 
  76.      */  
  77.     public long lastUpdateTime;  
  78.   
  79.     /** 
  80.      * All kernel group-IDs that have been assigned to this package. 
  81.      * This is only filled in if the flag {@link PackageManager#GET_GIDS} was set. 
  82.      */  
  83.     public int[] gids;  
  84.   
  85.     /** 
  86.      * Array of all {@link android.R.styleable#AndroidManifestActivity 
  87.      * <activity>} tags included under <application>, 
  88.      * or null if there were none.  This is only filled in if the flag 
  89.      * {@link PackageManager#GET_ACTIVITIES} was set. 
  90.      */  
  91.     public ActivityInfo[] activities;  
  92.   
  93.     /** 
  94.      * Array of all {@link android.R.styleable#AndroidManifestReceiver 
  95.      * <receiver>} tags included under <application>, 
  96.      * or null if there were none.  This is only filled in if the flag 
  97.      * {@link PackageManager#GET_RECEIVERS} was set. 
  98.      */  
  99.     public ActivityInfo[] receivers;  
  100.   
  101.     /** 
  102.      * Array of all {@link android.R.styleable#AndroidManifestService 
  103.      * <service>} tags included under <application>, 
  104.      * or null if there were none.  This is only filled in if the flag 
  105.      * {@link PackageManager#GET_SERVICES} was set. 
  106.      */  
  107.     public ServiceInfo[] services;  
  108.   
  109.     /** 
  110.      * Array of all {@link android.R.styleable#AndroidManifestProvider 
  111.      * <provider>} tags included under <application>, 
  112.      * or null if there were none.  This is only filled in if the flag 
  113.      * {@link PackageManager#GET_PROVIDERS} was set. 
  114.      */  
  115.     public ProviderInfo[] providers;  
  116.   
  117.     /** 
  118.      * Array of all {@link android.R.styleable#AndroidManifestInstrumentation 
  119.      * <instrumentation>} tags included under <manifest>, 
  120.      * or null if there were none.  This is only filled in if the flag 
  121.      * {@link PackageManager#GET_INSTRUMENTATION} was set. 
  122.      */  
  123.     public InstrumentationInfo[] instrumentation;  
  124.       
  125.     /** 
  126.      * Array of all {@link android.R.styleable#AndroidManifestPermission 
  127.      * <permission>} tags included under <manifest>, 
  128.      * or null if there were none.  This is only filled in if the flag 
  129.      * {@link PackageManager#GET_PERMISSIONS} was set. 
  130.      */  
  131.     public PermissionInfo[] permissions;  
  132.       
  133.     /** 
  134.      * Array of all {@link android.R.styleable#AndroidManifestUsesPermission 
  135.      * <uses-permission>} tags included under <manifest>, 
  136.      * or null if there were none.  This is only filled in if the flag 
  137.      * {@link PackageManager#GET_PERMISSIONS} was set.  This list includes 
  138.      * all permissions requested, even those that were not granted or known 
  139.      * by the system at install time. 
  140.      */  
  141.     public String[] requestedPermissions;  
  142.       
  143.     /** 
  144.      * Array of flags of all {@link android.R.styleable#AndroidManifestUsesPermission 
  145.      * <uses-permission>} tags included under <manifest>, 
  146.      * or null if there were none.  This is only filled in if the flag 
  147.      * {@link PackageManager#GET_PERMISSIONS} was set.  Each value matches 
  148.      * the corresponding entry in {@link #requestedPermissions}, and will have 
  149.      * the flags {@link #REQUESTED_PERMISSION_REQUIRED} and 
  150.      * {@link #REQUESTED_PERMISSION_GRANTED} set as appropriate. 
  151.      */  
  152.     public int[] requestedPermissionsFlags;  
  153.   
  154.     /** 
  155.      * Flag for {@link #requestedPermissionsFlags}: the requested permission 
  156.      * is required for the application to run; the user can not optionally 
  157.      * disable it.  Currently all permissions are required. 
  158.      */  
  159.     public static final int REQUESTED_PERMISSION_REQUIRED = 1<<0;  
  160.   
  161.     /** 
  162.      * Flag for {@link #requestedPermissionsFlags}: the requested permission 
  163.      * is currently granted to the application. 
  164.      */  
  165.     public static final int REQUESTED_PERMISSION_GRANTED = 1<<1;  
  166.   
  167.     /** 
  168.      * Array of all signatures read from the package file.  This is only filled 
  169.      * in if the flag {@link PackageManager#GET_SIGNATURES} was set. 
  170.      */  
  171.     public Signature[] signatures;  
  172.       
  173.     /** 
  174.      * Application specified preferred configuration 
  175.      * {@link android.R.styleable#AndroidManifestUsesConfiguration 
  176.      * <uses-configuration>} tags included under <manifest>, 
  177.      * or null if there were none. This is only filled in if the flag 
  178.      * {@link PackageManager#GET_CONFIGURATIONS} was set.   
  179.      */  
  180.     public ConfigurationInfo[] configPreferences;  
  181.   
  182.     /** 
  183.      * The features that this application has said it requires. 
  184.      */  
  185.     public FeatureInfo[] reqFeatures;  
  186.   
  187.     /** 
  188.      * Constant corresponding to <code>auto</code> in 
  189.      * the {@link android.R.attr#installLocation} attribute. 
  190.      * @hide 
  191.      */  
  192.     public static final int INSTALL_LOCATION_UNSPECIFIED = -1;  
  193.     /** 
  194.      * Constant corresponding to <code>auto</code> in 
  195.      * the {@link android.R.attr#installLocation} attribute. 
  196.      * @hide 
  197.      */  
  198.     public static final int INSTALL_LOCATION_AUTO = 0;  
  199.     /** 
  200.      * Constant corresponding to <code>internalOnly</code> in 
  201.      * the {@link android.R.attr#installLocation} attribute. 
  202.      * @hide 
  203.      */  
  204.     public static final int INSTALL_LOCATION_INTERNAL_ONLY = 1;  
  205.     /** 
  206.      * Constant corresponding to <code>preferExternal</code> in 
  207.      * the {@link android.R.attr#installLocation} attribute. 
  208.      * @hide 
  209.      */  
  210.     public static final int INSTALL_LOCATION_PREFER_EXTERNAL = 2;  
  211.     /** 
  212.      * The install location requested by the activity.  From the 
  213.      * {@link android.R.attr#installLocation} attribute, one of 
  214.      * {@link #INSTALL_LOCATION_AUTO}, 
  215.      * {@link #INSTALL_LOCATION_INTERNAL_ONLY}, 
  216.      * {@link #INSTALL_LOCATION_PREFER_EXTERNAL} 
  217.      * @hide 
  218.      */  
  219.     public int installLocation = INSTALL_LOCATION_INTERNAL_ONLY;  
  220.       
  221.     public PackageInfo() {  
  222.     }  
  223.   
  224.     public String toString() {  
  225.         return "PackageInfo{"  
  226.             + Integer.toHexString(System.identityHashCode(this))  
  227.             + " " + packageName + "}";  
  228.     }  
  229.   
  230.     public int describeContents() {  
  231.         return 0;  
  232.     }  
  233.   
  234.     public void writeToParcel(Parcel dest, int parcelableFlags) {  
  235.         dest.writeString(packageName);  
  236.         dest.writeInt(versionCode);  
  237.         dest.writeString(versionName);  
  238.         dest.writeString(sharedUserId);  
  239.         dest.writeInt(sharedUserLabel);  
  240.         if (applicationInfo != null) {  
  241.             dest.writeInt(1);  
  242.             applicationInfo.writeToParcel(dest, parcelableFlags);  
  243.         } else {  
  244.             dest.writeInt(0);  
  245.         }  
  246.         dest.writeLong(firstInstallTime);  
  247.         dest.writeLong(lastUpdateTime);  
  248.         dest.writeIntArray(gids);  
  249.         dest.writeTypedArray(activities, parcelableFlags);  
  250.         dest.writeTypedArray(receivers, parcelableFlags);  
  251.         dest.writeTypedArray(services, parcelableFlags);  
  252.         dest.writeTypedArray(providers, parcelableFlags);  
  253.         dest.writeTypedArray(instrumentation, parcelableFlags);  
  254.         dest.writeTypedArray(permissions, parcelableFlags);  
  255.         dest.writeStringArray(requestedPermissions);  
  256.         dest.writeIntArray(requestedPermissionsFlags);  
  257.         dest.writeTypedArray(signatures, parcelableFlags);  
  258.         dest.writeTypedArray(configPreferences, parcelableFlags);  
  259.         dest.writeTypedArray(reqFeatures, parcelableFlags);  
  260.         dest.writeInt(installLocation);  
  261.     }  
  262.   
  263.     public static final Parcelable.Creator<PackageInfo> CREATOR  
  264.             = new Parcelable.Creator<PackageInfo>() {  
  265.         public PackageInfo createFromParcel(Parcel source) {  
  266.             return new PackageInfo(source);  
  267.         }  
  268.   
  269.         public PackageInfo[] newArray(int size) {  
  270.             return new PackageInfo[size];  
  271.         }  
  272.     };  
  273.   
  274.     private PackageInfo(Parcel source) {  
  275.        <span style="color:#3333ff;"> packageName = source.readString();  
  276.         versionCode = source.readInt();  
  277.         versionName = source.readString();</span>  
  278.         sharedUserId = source.readString();  
  279.         sharedUserLabel = source.readInt();  
  280.         int hasApp = source.readInt();  
  281.         if (hasApp != 0) {  
  282.             applicationInfo = ApplicationInfo.CREATOR.createFromParcel(source);  
  283.         }  
  284.         <span style="color:#333399;">firstInstallTime = source.readLong();  
  285.         lastUpdateTime = source.readLong();</span>  
  286.         gids = source.createIntArray();  
  287.         activities = source.createTypedArray(ActivityInfo.CREATOR);  
  288.         receivers = source.createTypedArray(ActivityInfo.CREATOR);  
  289.         services = source.createTypedArray(ServiceInfo.CREATOR);  
  290.         providers = source.createTypedArray(ProviderInfo.CREATOR);  
  291.         instrumentation = source.createTypedArray(InstrumentationInfo.CREATOR);  
  292.         permissions = source.createTypedArray(PermissionInfo.CREATOR);  
  293.         requestedPermissions = source.createStringArray();  
  294.         requestedPermissionsFlags = source.createIntArray();  
  295.         signatures = source.createTypedArray(Signature.CREATOR);  
  296.         configPreferences = source.createTypedArray(ConfigurationInfo.CREATOR);  
  297.         reqFeatures = source.createTypedArray(FeatureInfo.CREATOR);  
  298.         installLocation = source.readInt();  
  299.     }  
  300. }  

ApplicationInfo.java源码:

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. /* 
  2.  * Copyright (C) 2007 The Android Open Source Project 
  3.  * 
  4.  * Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  * you may not use this file except in compliance with the License. 
  6.  * You may obtain a copy of the License at 
  7.  * 
  8.  *      http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  * Unless required by applicable law or agreed to in writing, software 
  11.  * distributed under the License is distributed on an "AS IS" BASIS, 
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  * See the License for the specific language governing permissions and 
  14.  * limitations under the License. 
  15.  */  
  16.   
  17. package android.content.pm;  
  18.   
  19. import android.content.pm.PackageManager.NameNotFoundException;  
  20. import android.content.res.Resources;  
  21. import android.graphics.drawable.Drawable;  
  22. import android.os.Parcel;  
  23. import android.os.Parcelable;  
  24. import android.util.Printer;  
  25.   
  26. import java.text.Collator;  
  27. import java.util.Comparator;  
  28.   
  29. /** 
  30.  * Information you can retrieve about a particular application.  This 
  31.  * corresponds to information collected from the AndroidManifest.xml's 
  32.  * <application> tag. 
  33.  */  
  34. public class ApplicationInfo extends PackageItemInfo implements Parcelable {  
  35.       
  36.     /** 
  37.      * Default task affinity of all activities in this application. See  
  38.      * {@link ActivityInfo#taskAffinity} for more information.  This comes  
  39.      * from the "taskAffinity" attribute.  
  40.      */  
  41.     public String taskAffinity;  
  42.       
  43.     /** 
  44.      * Optional name of a permission required to be able to access this 
  45.      * application's components.  From the "permission" attribute. 
  46.      */  
  47.     public String permission;  
  48.       
  49.     /** 
  50.      * The name of the process this application should run in.  From the 
  51.      * "process" attribute or, if not set, the same as 
  52.      * <var>packageName</var>. 
  53.      */  
  54.     public String processName;  
  55.       
  56.     /** 
  57.      * Class implementing the Application object.  From the "class" 
  58.      * attribute. 
  59.      */  
  60.     public String className;  
  61.       
  62.     /** 
  63.      * A style resource identifier (in the package's resources) of the 
  64.      * description of an application.  From the "description" attribute 
  65.      * or, if not set, 0. 
  66.      */  
  67.     public int descriptionRes;      
  68.       
  69.     /** 
  70.      * A style resource identifier (in the package's resources) of the 
  71.      * default visual theme of the application.  From the "theme" attribute 
  72.      * or, if not set, 0. 
  73.      */  
  74.     public int theme;  
  75.       
  76.     /** 
  77.      * Class implementing the Application's manage space 
  78.      * functionality.  From the "manageSpaceActivity" 
  79.      * attribute. This is an optional attribute and will be null if 
  80.      * applications don't specify it in their manifest 
  81.      */  
  82.     public String manageSpaceActivityName;      
  83.       
  84.     /** 
  85.      * Class implementing the Application's backup functionality.  From 
  86.      * the "backupAgent" attribute.  This is an optional attribute and 
  87.      * will be null if the application does not specify it in its manifest. 
  88.      *  
  89.      * <p>If android:allowBackup is set to false, this attribute is ignored. 
  90.      */  
  91.     public String backupAgentName;  
  92.   
  93.     /** 
  94.      * The default extra UI options for activities in this application. 
  95.      * Set from the {@link android.R.attr#uiOptions} attribute in the 
  96.      * activity's manifest. 
  97.      */  
  98.     public int uiOptions = 0;  
  99.   
  100.     /** 
  101.      * Value for {@link #flags}: if set, this application is installed in the 
  102.      * device's system image. 
  103.      */  
  104.     public static final int FLAG_SYSTEM = 1<<0;  
  105.       
  106.     /** 
  107.      * Value for {@link #flags}: set to true if this application would like to 
  108.      * allow debugging of its 
  109.      * code, even when installed on a non-development system.  Comes 
  110.      * from {@link android.R.styleable#AndroidManifestApplication_debuggable 
  111.      * android:debuggable} of the <application> tag. 
  112.      */  
  113.     public static final int FLAG_DEBUGGABLE = 1<<1;  
  114.       
  115.     /** 
  116.      * Value for {@link #flags}: set to true if this application has code 
  117.      * associated with it.  Comes 
  118.      * from {@link android.R.styleable#AndroidManifestApplication_hasCode 
  119.      * android:hasCode} of the <application> tag. 
  120.      */  
  121.     public static final int FLAG_HAS_CODE = 1<<2;  
  122.       
  123.     /** 
  124.      * Value for {@link #flags}: set to true if this application is persistent. 
  125.      * Comes from {@link android.R.styleable#AndroidManifestApplication_persistent 
  126.      * android:persistent} of the <application> tag. 
  127.      */  
  128.     public static final int FLAG_PERSISTENT = 1<<3;  
  129.   
  130.     /** 
  131.      * Value for {@link #flags}: set to true if this application holds the 
  132.      * {@link android.Manifest.permission#FACTORY_TEST} permission and the 
  133.      * device is running in factory test mode. 
  134.      */  
  135.     public static final int FLAG_FACTORY_TEST = 1<<4;  
  136.   
  137.     /** 
  138.      * Value for {@link #flags}: default value for the corresponding ActivityInfo flag. 
  139.      * Comes from {@link android.R.styleable#AndroidManifestApplication_allowTaskReparenting 
  140.      * android:allowTaskReparenting} of the <application> tag. 
  141.      */  
  142.     public static final int FLAG_ALLOW_TASK_REPARENTING = 1<<5;  
  143.       
  144.     /** 
  145.      * Value for {@link #flags}: default value for the corresponding ActivityInfo flag. 
  146.      * Comes from {@link android.R.styleable#AndroidManifestApplication_allowClearUserData 
  147.      * android:allowClearUserData} of the <application> tag. 
  148.      */  
  149.     public static final int FLAG_ALLOW_CLEAR_USER_DATA = 1<<6;  
  150.       
  151.     /** 
  152.      * Value for {@link #flags}: this is set if this application has been 
  153.      * install as an update to a built-in system application. 
  154.      */  
  155.     public static final int FLAG_UPDATED_SYSTEM_APP = 1<<7;  
  156.       
  157.     /** 
  158.      * Value for {@link #flags}: this is set of the application has specified 
  159.      * {@link android.R.styleable#AndroidManifestApplication_testOnly 
  160.      * android:testOnly} to be true. 
  161.      */  
  162.     public static final int FLAG_TEST_ONLY = 1<<8;  
  163.   
  164.     /** 
  165.      * Value for {@link #flags}: true when the application's window can be 
  166.      * reduced in size for smaller screens.  Corresponds to 
  167.      * {@link android.R.styleable#AndroidManifestSupportsScreens_smallScreens 
  168.      * android:smallScreens}. 
  169.      */  
  170.     public static final int FLAG_SUPPORTS_SMALL_SCREENS = 1<<9;  
  171.       
  172.     /** 
  173.      * Value for {@link #flags}: true when the application's window can be 
  174.      * displayed on normal screens.  Corresponds to 
  175.      * {@link android.R.styleable#AndroidManifestSupportsScreens_normalScreens 
  176.      * android:normalScreens}. 
  177.      */  
  178.     public static final int FLAG_SUPPORTS_NORMAL_SCREENS = 1<<10;   
  179.       
  180.     /** 
  181.      * Value for {@link #flags}: true when the application's window can be 
  182.      * increased in size for larger screens.  Corresponds to 
  183.      * {@link android.R.styleable#AndroidManifestSupportsScreens_largeScreens 
  184.      * android:largeScreens}. 
  185.      */  
  186.     public static final int FLAG_SUPPORTS_LARGE_SCREENS = 1<<11;  
  187.       
  188.     /** 
  189.      * Value for {@link #flags}: true when the application knows how to adjust 
  190.      * its UI for different screen sizes.  Corresponds to 
  191.      * {@link android.R.styleable#AndroidManifestSupportsScreens_resizeable 
  192.      * android:resizeable}. 
  193.      */  
  194.     public static final int FLAG_RESIZEABLE_FOR_SCREENS = 1<<12;  
  195.       
  196.     /** 
  197.      * Value for {@link #flags}: true when the application knows how to 
  198.      * accomodate different screen densities.  Corresponds to 
  199.      * {@link android.R.styleable#AndroidManifestSupportsScreens_anyDensity 
  200.      * android:anyDensity}. 
  201.      */  
  202.     public static final int FLAG_SUPPORTS_SCREEN_DENSITIES = 1<<13;  
  203.       
  204.     /** 
  205.      * Value for {@link #flags}: set to true if this application would like to 
  206.      * request the VM to operate under the safe mode. Comes from 
  207.      * {@link android.R.styleable#AndroidManifestApplication_vmSafeMode 
  208.      * android:vmSafeMode} of the <application> tag. 
  209.      */  
  210.     public static final int FLAG_VM_SAFE_MODE = 1<<14;  
  211.   
  212.     /** 
  213.      * Value for {@link #flags}: set to <code>false</code> if the application does not wish 
  214.      * to permit any OS-driven backups of its data; <code>true</code> otherwise. 
  215.      *  
  216.      * <p>Comes from the 
  217.      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup} 
  218.      * attribute of the <application> tag. 
  219.      */  
  220.     public static final int FLAG_ALLOW_BACKUP = 1<<15;  
  221.   
  222.     /** 
  223.      * Value for {@link #flags}: set to <code>false</code> if the application must be kept 
  224.      * in memory following a full-system restore operation; <code>true</code> otherwise. 
  225.      * Ordinarily, during a full system restore operation each application is shut down 
  226.      * following execution of its agent's onRestore() method.  Setting this attribute to 
  227.      * <code>false</code> prevents this.  Most applications will not need to set this attribute. 
  228.      * 
  229.      * <p>If 
  230.      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup} 
  231.      * is set to <code>false</code> or no 
  232.      * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent} 
  233.      * is specified, this flag will be ignored. 
  234.      * 
  235.      * <p>Comes from the 
  236.      * {@link android.R.styleable#AndroidManifestApplication_killAfterRestore android:killAfterRestore} 
  237.      * attribute of the <application> tag. 
  238.      */  
  239.     public static final int FLAG_KILL_AFTER_RESTORE = 1<<16;  
  240.   
  241.     /** 
  242.      * Value for {@link #flags}: Set to <code>true</code> if the application's backup 
  243.      * agent claims to be able to handle restore data even "from the future," 
  244.      * i.e. from versions of the application with a versionCode greater than 
  245.      * the one currently installed on the device.  <i>Use with caution!</i>  By default 
  246.      * this attribute is <code>false</code> and the Backup Manager will ensure that data 
  247.      * from "future" versions of the application are never supplied during a restore operation. 
  248.      * 
  249.      * <p>If 
  250.      * {@link android.R.styleable#AndroidManifestApplication_allowBackup android:allowBackup} 
  251.      * is set to <code>false</code> or no 
  252.      * {@link android.R.styleable#AndroidManifestApplication_backupAgent android:backupAgent} 
  253.      * is specified, this flag will be ignored. 
  254.      * 
  255.      * <p>Comes from the 
  256.      * {@link android.R.styleable#AndroidManifestApplication_restoreAnyVersion android:restoreAnyVersion} 
  257.      * attribute of the <application> tag. 
  258.      */  
  259.     public static final int FLAG_RESTORE_ANY_VERSION = 1<<17;  
  260.   
  261.     /** 
  262.      * Value for {@link #flags}: Set to true if the application is 
  263.      * currently installed on external/removable/unprotected storage.  Such 
  264.      * applications may not be available if their storage is not currently 
  265.      * mounted.  When the storage it is on is not available, it will look like 
  266.      * the application has been uninstalled (its .apk is no longer available) 
  267.      * but its persistent data is not removed. 
  268.      */  
  269.     public static final int FLAG_EXTERNAL_STORAGE = 1<<18;  
  270.   
  271.     /** 
  272.      * Value for {@link #flags}: true when the application's window can be 
  273.      * increased in size for extra large screens.  Corresponds to 
  274.      * {@link android.R.styleable#AndroidManifestSupportsScreens_xlargeScreens 
  275.      * android:xlargeScreens}. 
  276.      */  
  277.     public static final int FLAG_SUPPORTS_XLARGE_SCREENS = 1<<19;  
  278.       
  279.     /** 
  280.      * Value for {@link #flags}: true when the application has requested a 
  281.      * large heap for its processes.  Corresponds to 
  282.      * {@link android.R.styleable#AndroidManifestApplication_largeHeap 
  283.      * android:largeHeap}. 
  284.      */  
  285.     public static final int FLAG_LARGE_HEAP = 1<<20;  
  286.   
  287.     /** 
  288.      * Value for {@link #flags}: true if this application's package is in 
  289.      * the stopped state. 
  290.      */  
  291.     public static final int FLAG_STOPPED = 1<<21;  
  292.   
  293.     /** 
  294.      * Value for {@link #flags}: true  when the application is willing to support 
  295.      * RTL (right to left). All activities will inherit this value. 
  296.      * 
  297.      * Set from the {@link android.R.attr#supportsRtl} attribute in the 
  298.      * activity's manifest. 
  299.      * 
  300.      * Default value is false (no support for RTL). 
  301.      */  
  302.     public static final int FLAG_SUPPORTS_RTL = 1<<22;  
  303.   
  304.     /** 
  305.      * Value for {@link #flags}: true if the application is currently 
  306.      * installed for the calling user. 
  307.      */  
  308.     public static final int FLAG_INSTALLED = 1<<23;  
  309.   
  310.     /** 
  311.      * Value for {@link #flags}: true if the application only has its 
  312.      * data installed; the application package itself does not currently 
  313.      * exist on the device. 
  314.      */  
  315.     public static final int FLAG_IS_DATA_ONLY = 1<<24;  
  316.   
  317.     /** 
  318.      * Value for {@link #flags}: Set to true if the application has been 
  319.      * installed using the forward lock option. 
  320.      * 
  321.      * NOTE: DO NOT CHANGE THIS VALUE!  It is saved in packages.xml. 
  322.      *  
  323.      * {@hide} 
  324.      */  
  325.     public static final int FLAG_FORWARD_LOCK = 1<<29;  
  326.   
  327.     /** 
  328.      * Value for {@link #flags}: set to <code>true</code> if the application 
  329.      * has reported that it is heavy-weight, and thus can not participate in 
  330.      * the normal application lifecycle. 
  331.      * 
  332.      * <p>Comes from the 
  333.      * {@link android.R.styleable#AndroidManifestApplication_cantSaveState android:cantSaveState} 
  334.      * attribute of the <application> tag. 
  335.      * 
  336.      * {@hide} 
  337.      */  
  338.     public static final int FLAG_CANT_SAVE_STATE = 1<<28;  
  339.   
  340.     /** 
  341.      * Flags associated with the application.  Any combination of 
  342.      * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE}, 
  343.      * {@link #FLAG_PERSISTENT}, {@link #FLAG_FACTORY_TEST}, and 
  344.      * {@link #FLAG_ALLOW_TASK_REPARENTING} 
  345.      * {@link #FLAG_ALLOW_CLEAR_USER_DATA}, {@link #FLAG_UPDATED_SYSTEM_APP}, 
  346.      * {@link #FLAG_TEST_ONLY}, {@link #FLAG_SUPPORTS_SMALL_SCREENS}, 
  347.      * {@link #FLAG_SUPPORTS_NORMAL_SCREENS}, 
  348.      * {@link #FLAG_SUPPORTS_LARGE_SCREENS}, {@link #FLAG_SUPPORTS_XLARGE_SCREENS}, 
  349.      * {@link #FLAG_RESIZEABLE_FOR_SCREENS}, 
  350.      * {@link #FLAG_SUPPORTS_SCREEN_DENSITIES}, {@link #FLAG_VM_SAFE_MODE}, 
  351.      * {@link #FLAG_INSTALLED}. 
  352.      */  
  353.     public int flags = 0;  
  354.       
  355.     /** 
  356.      * The required smallest screen width the application can run on.  If 0, 
  357.      * nothing has been specified.  Comes from 
  358.      * {@link android.R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp 
  359.      * android:requiresSmallestWidthDp} attribute of the <supports-screens> tag. 
  360.      */  
  361.     public int requiresSmallestWidthDp = 0;  
  362.   
  363.     /** 
  364.      * The maximum smallest screen width the application is designed for.  If 0, 
  365.      * nothing has been specified.  Comes from 
  366.      * {@link android.R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp 
  367.      * android:compatibleWidthLimitDp} attribute of the <supports-screens> tag. 
  368.      */  
  369.     public int compatibleWidthLimitDp = 0;  
  370.   
  371.     /** 
  372.      * The maximum smallest screen width the application will work on.  If 0, 
  373.      * nothing has been specified.  Comes from 
  374.      * {@link android.R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp 
  375.      * android:largestWidthLimitDp} attribute of the <supports-screens> tag. 
  376.      */  
  377.     public int largestWidthLimitDp = 0;  
  378.   
  379.     /** 
  380.      * Full path to the location of this package. 
  381.      */  
  382.     public String sourceDir;  
  383.   
  384.     /** 
  385.      * Full path to the location of the publicly available parts of this 
  386.      * package (i.e. the primary resource package and manifest).  For 
  387.      * non-forward-locked apps this will be the same as {@link #sourceDir). 
  388.      */  
  389.     public String publicSourceDir;  
  390.       
  391.     /** 
  392.      * Full paths to the locations of extra resource packages this application 
  393.      * uses. This field is only used if there are extra resource packages, 
  394.      * otherwise it is null. 
  395.      *  
  396.      * {@hide} 
  397.      */  
  398.     public String[] resourceDirs;  
  399.   
  400.     /** 
  401.      * Paths to all shared libraries this application is linked against.  This 
  402.      * field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES 
  403.      * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving 
  404.      * the structure. 
  405.      */  
  406.     public String[] sharedLibraryFiles;  
  407.       
  408.     /** 
  409.      * Full path to a directory assigned to the package for its persistent 
  410.      * data. 
  411.      */  
  412.     public String dataDir;  
  413.   
  414.     /** 
  415.      * Full path to the directory where native JNI libraries are stored. 
  416.      */  
  417.     public String nativeLibraryDir;  
  418.   
  419.     /** 
  420.      * The kernel user-ID that has been assigned to this application; 
  421.      * currently this is not a unique ID (multiple applications can have 
  422.      * the same uid). 
  423.      */  
  424.     public int uid;  
  425.       
  426.     /** 
  427.      * The minimum SDK version this application targets.  It may run on earlier 
  428.      * versions, but it knows how to work with any new behavior added at this 
  429.      * version.  Will be {@link android.os.Build.VERSION_CODES#CUR_DEVELOPMENT} 
  430.      * if this is a development build and the app is targeting that.  You should 
  431.      * compare that this number is >= the SDK version number at which your 
  432.      * behavior was introduced. 
  433.      */  
  434.     public int targetSdkVersion;  
  435.       
  436.     /** 
  437.      * When false, indicates that all components within this application are 
  438.      * considered disabled, regardless of their individually set enabled status. 
  439.      */  
  440.     public boolean enabled = true;  
  441.   
  442.     /** 
  443.      * For convenient access to the current enabled setting of this app. 
  444.      * @hide 
  445.      */  
  446.     public int enabledSetting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;  
  447.   
  448.     /** 
  449.      * For convenient access to package's install location. 
  450.      * @hide 
  451.      */  
  452.     public int installLocation = PackageInfo.INSTALL_LOCATION_UNSPECIFIED;  
  453.       
  454.     public void dump(Printer pw, String prefix) {  
  455.         super.dumpFront(pw, prefix);  
  456.         if (className != null) {  
  457.             pw.println(prefix + "className=" + className);  
  458.         }  
  459.         if (permission != null) {  
  460.             pw.println(prefix + "permission=" + permission);  
  461.         }  
  462.         pw.println(prefix + "processName=" + processName);  
  463.         pw.println(prefix + "taskAffinity=" + taskAffinity);  
  464.         pw.println(prefix + "uid=" + uid + " flags=0x" + Integer.toHexString(flags)  
  465.                 + " theme=0x" + Integer.toHexString(theme));  
  466.         pw.println(prefix + "requiresSmallestWidthDp=" + requiresSmallestWidthDp  
  467.                 + " compatibleWidthLimitDp=" + compatibleWidthLimitDp  
  468.                 + " largestWidthLimitDp=" + largestWidthLimitDp);  
  469.         pw.println(prefix + "sourceDir=" + sourceDir);  
  470.         if (sourceDir == null) {  
  471.             if (publicSourceDir != null) {  
  472.                 pw.println(prefix + "publicSourceDir=" + publicSourceDir);  
  473.             }  
  474.         } else if (!sourceDir.equals(publicSourceDir)) {  
  475.             pw.println(prefix + "publicSourceDir=" + publicSourceDir);  
  476.         }  
  477.         if (resourceDirs != null) {  
  478.             pw.println(prefix + "resourceDirs=" + resourceDirs);  
  479.         }  
  480.         pw.println(prefix + "dataDir=" + dataDir);  
  481.         if (sharedLibraryFiles != null) {  
  482.             pw.println(prefix + "sharedLibraryFiles=" + sharedLibraryFiles);  
  483.         }  
  484.         pw.println(prefix + "enabled=" + enabled + " targetSdkVersion=" + targetSdkVersion);  
  485.         if (manageSpaceActivityName != null) {  
  486.             pw.println(prefix + "manageSpaceActivityName="+manageSpaceActivityName);  
  487.         }  
  488.         if (descriptionRes != 0) {  
  489.             pw.println(prefix + "description=0x"+Integer.toHexString(descriptionRes));  
  490.         }  
  491.         if (uiOptions != 0) {  
  492.             pw.println(prefix + "uiOptions=0x" + Integer.toHexString(uiOptions));  
  493.         }  
  494.         pw.println(prefix + "supportsRtl=" + (hasRtlSupport() ? "true" : "false"));  
  495.         super.dumpBack(pw, prefix);  
  496.     }  
  497.   
  498.     /** 
  499.      * @return true if "supportsRtl" has been set to true in the AndroidManifest 
  500.      * @hide 
  501.      */  
  502.     public boolean hasRtlSupport() {  
  503.         return (flags & FLAG_SUPPORTS_RTL) == FLAG_SUPPORTS_RTL;  
  504.     }  
  505.       
  506.     public static class DisplayNameComparator  
  507.             implements Comparator<ApplicationInfo> {  
  508.         public DisplayNameComparator(PackageManager pm) {  
  509.             mPM = pm;  
  510.         }  
  511.   
  512.         public final int compare(ApplicationInfo aa, ApplicationInfo ab) {  
  513.             CharSequence  sa = mPM.getApplicationLabel(aa);  
  514.             if (sa == null) {  
  515.                 sa = aa.packageName;  
  516.             }  
  517.             CharSequence  sb = mPM.getApplicationLabel(ab);  
  518.             if (sb == null) {  
  519.                 sb = ab.packageName;  
  520.             }  
  521.               
  522.             return sCollator.compare(sa.toString(), sb.toString());  
  523.         }  
  524.   
  525.         private final Collator   sCollator = Collator.getInstance();  
  526.         private PackageManager   mPM;  
  527.     }  
  528.   
  529.     public ApplicationInfo() {  
  530.     }  
  531.       
  532.     public ApplicationInfo(ApplicationInfo orig) {  
  533.         super(orig);  
  534.         taskAffinity = orig.taskAffinity;  
  535.         permission = orig.permission;  
  536.         processName = orig.processName;  
  537.         className = orig.className;  
  538.         theme = orig.theme;  
  539.         flags = orig.flags;  
  540.         requiresSmallestWidthDp = orig.requiresSmallestWidthDp;  
  541.         compatibleWidthLimitDp = orig.compatibleWidthLimitDp;  
  542.         largestWidthLimitDp = orig.largestWidthLimitDp;  
  543.         sourceDir = orig.sourceDir;  
  544.         publicSourceDir = orig.publicSourceDir;  
  545.         nativeLibraryDir = orig.nativeLibraryDir;  
  546.         resourceDirs = orig.resourceDirs;  
  547.         sharedLibraryFiles = orig.sharedLibraryFiles;  
  548.         dataDir = orig.dataDir;  
  549.         uid = orig.uid;  
  550.         targetSdkVersion = orig.targetSdkVersion;  
  551.         enabled = orig.enabled;  
  552.         enabledSetting = orig.enabledSetting;  
  553.         installLocation = orig.installLocation;  
  554.         manageSpaceActivityName = orig.manageSpaceActivityName;  
  555.         descriptionRes = orig.descriptionRes;  
  556.         uiOptions = orig.uiOptions;  
  557.         backupAgentName = orig.backupAgentName;  
  558.     }  
  559.   
  560.   
  561.     public String toString() {  
  562.         return "ApplicationInfo{"  
  563.             + Integer.toHexString(System.identityHashCode(this))  
  564.             + " " + packageName + "}";  
  565.     }  
  566.   
  567.     public int describeContents() {  
  568.         return 0;  
  569.     }  
  570.   
  571.     public void writeToParcel(Parcel dest, int parcelableFlags) {  
  572.         super.writeToParcel(dest, parcelableFlags);  
  573.         dest.writeString(taskAffinity);  
  574.         dest.writeString(permission);  
  575.         dest.writeString(processName);  
  576.         dest.writeString(className);  
  577.         dest.writeInt(theme);  
  578.         dest.writeInt(flags);  
  579.         dest.writeInt(requiresSmallestWidthDp);  
  580.         dest.writeInt(compatibleWidthLimitDp);  
  581.         dest.writeInt(largestWidthLimitDp);  
  582.         dest.writeString(sourceDir);  
  583.         dest.writeString(publicSourceDir);  
  584.         dest.writeString(nativeLibraryDir);  
  585.         dest.writeStringArray(resourceDirs);  
  586.         dest.writeStringArray(sharedLibraryFiles);  
  587.         dest.writeString(dataDir);  
  588.         dest.writeInt(uid);  
  589.         dest.writeInt(targetSdkVersion);  
  590.         dest.writeInt(enabled ? 1 : 0);  
  591.         dest.writeInt(enabledSetting);  
  592.         dest.writeInt(installLocation);  
  593.         dest.writeString(manageSpaceActivityName);  
  594.         dest.writeString(backupAgentName);  
  595.         dest.writeInt(descriptionRes);  
  596.         dest.writeInt(uiOptions);  
  597.     }  
  598.   
  599.     public static final Parcelable.Creator<ApplicationInfo> CREATOR  
  600.             = new Parcelable.Creator<ApplicationInfo>() {  
  601.         public ApplicationInfo createFromParcel(Parcel source) {  
  602.             return new ApplicationInfo(source);  
  603.         }  
  604.         public ApplicationInfo[] newArray(int size) {  
  605.             return new ApplicationInfo[size];  
  606.         }  
  607.     };  
  608.   
  609.     private ApplicationInfo(Parcel source) {  
  610.         super(source);  
  611.         taskAffinity = source.readString();  
  612.         permission = source.readString();  
  613.         processName = source.readString();  
  614.         className = source.readString();  
  615.         theme = source.readInt();  
  616.         flags = source.readInt();  
  617.         requiresSmallestWidthDp = source.readInt();  
  618.         compatibleWidthLimitDp = source.readInt();  
  619.         largestWidthLimitDp = source.readInt();  
  620.         sourceDir = source.readString();  
  621.         publicSourceDir = source.readString();  
  622.         nativeLibraryDir = source.readString();  
  623.         resourceDirs = source.readStringArray();  
  624.         sharedLibraryFiles = source.readStringArray();  
  625.         dataDir = source.readString();  
  626.         uid = source.readInt();  
  627.         targetSdkVersion = source.readInt();  
  628.         enabled = source.readInt() != 0;  
  629.         enabledSetting = source.readInt();  
  630.         installLocation = source.readInt();  
  631.         manageSpaceActivityName = source.readString();  
  632.         backupAgentName = source.readString();  
  633.         descriptionRes = source.readInt();  
  634.         uiOptions = source.readInt();  
  635.     }  
  636.   
  637.     /** 
  638.      * Retrieve the textual description of the application.  This 
  639.      * will call back on the given PackageManager to load the description from 
  640.      * the application. 
  641.      * 
  642.      * @param pm A PackageManager from which the label can be loaded; usually 
  643.      * the PackageManager from which you originally retrieved this item. 
  644.      * 
  645.      * @return Returns a CharSequence containing the application's description. 
  646.      * If there is no description, null is returned. 
  647.      */  
  648.     public CharSequence loadDescription(PackageManager pm) {  
  649.         if (descriptionRes != 0) {  
  650.             CharSequence label = pm.getText(packageName, descriptionRes, this);  
  651.             if (label != null) {  
  652.                 return label;  
  653.             }  
  654.         }  
  655.         return null;  
  656.     }  
  657.   
  658.     /** 
  659.      * Disable compatibility mode 
  660.      *  
  661.      * @hide 
  662.      */  
  663.     public void disableCompatibilityMode() {  
  664.         flags |= (FLAG_SUPPORTS_LARGE_SCREENS | FLAG_SUPPORTS_NORMAL_SCREENS |  
  665.                 FLAG_SUPPORTS_SMALL_SCREENS | FLAG_RESIZEABLE_FOR_SCREENS |  
  666.                 FLAG_SUPPORTS_SCREEN_DENSITIES | FLAG_SUPPORTS_XLARGE_SCREENS);  
  667.     }  
  668.       
  669.     /** 
  670.      * @hide 
  671.      */  
  672.     @Override protected Drawable loadDefaultIcon(PackageManager pm) {  
  673.         if ((flags & FLAG_EXTERNAL_STORAGE) != 0  
  674.                 && isPackageUnavailable(pm)) {  
  675.             return Resources.getSystem().getDrawable(  
  676.                     com.android.internal.R.drawable.sym_app_on_sd_unavailable_icon);  
  677.         }  
  678.         return pm.getDefaultActivityIcon();  
  679.     }  
  680.       
  681.     private boolean isPackageUnavailable(PackageManager pm) {  
  682.         try {  
  683.             return pm.getPackageInfo(packageName, 0) == null;  
  684.         } catch (NameNotFoundException ex) {  
  685.             return true;  
  686.         }  
  687.     }  
  688.       
  689.     /** 
  690.      * @hide 
  691.      */  
  692.     @Override protected ApplicationInfo getApplicationInfo() {  
  693.         return this;  
  694.     }  
  695. }  

PackageItemInfo.java源码:

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. /* 
  2.  * Copyright (C) 2007 The Android Open Source Project 
  3.  * 
  4.  * Licensed under the Apache License, Version 2.0 (the "License"); 
  5.  * you may not use this file except in compliance with the License. 
  6.  * You may obtain a copy of the License at 
  7.  * 
  8.  *      http://www.apache.org/licenses/LICENSE-2.0 
  9.  * 
  10.  * Unless required by applicable law or agreed to in writing, software 
  11.  * distributed under the License is distributed on an "AS IS" BASIS, 
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  13.  * See the License for the specific language governing permissions and 
  14.  * limitations under the License. 
  15.  */  
  16.   
  17. package android.content.pm;  
  18.   
  19. import android.content.res.XmlResourceParser;  
  20.   
  21. import android.graphics.drawable.Drawable;  
  22. import android.os.Bundle;  
  23. import android.os.Parcel;  
  24. import android.text.TextUtils;  
  25. import android.util.Printer;  
  26.   
  27. import java.text.Collator;  
  28. import java.util.Comparator;  
  29.   
  30. /** 
  31.  * Base class containing information common to all package items held by 
  32.  * the package manager.  This provides a very common basic set of attributes: 
  33.  * a label, icon, and meta-data.  This class is not intended 
  34.  * to be used by itself; it is simply here to share common definitions 
  35.  * between all items returned by the package manager.  As such, it does not 
  36.  * itself implement Parcelable, but does provide convenience methods to assist 
  37.  * in the implementation of Parcelable in subclasses. 
  38.  */  
  39. public class PackageItemInfo {  
  40.     /** 
  41.      * Public name of this item. From the "android:name" attribute. 
  42.      */  
  43.     public String name;  
  44.       
  45.     /** 
  46.      * Name of the package that this item is in. 
  47.      */  
  48.     public String packageName;  
  49.       
  50.     /** 
  51.      * A string resource identifier (in the package's resources) of this 
  52.      * component's label.  From the "label" attribute or, if not set, 0. 
  53.      */  
  54.     public int labelRes;  
  55.       
  56.     /** 
  57.      * The string provided in the AndroidManifest file, if any.  You 
  58.      * probably don't want to use this.  You probably want 
  59.      * {@link PackageManager#getApplicationLabel} 
  60.      */  
  61.     public CharSequence nonLocalizedLabel;  
  62.       
  63.     /** 
  64.      * A drawable resource identifier (in the package's resources) of this 
  65.      * component's icon.  From the "icon" attribute or, if not set, 0. 
  66.      */  
  67.     public int icon;  
  68.       
  69.     /** 
  70.      * A drawable resource identifier (in the package's resources) of this 
  71.      * component's logo. Logos may be larger/wider than icons and are 
  72.      * displayed by certain UI elements in place of a name or name/icon 
  73.      * combination. From the "logo" attribute or, if not set, 0.  
  74.      */  
  75.     public int logo;  
  76.       
  77.     /** 
  78.      * Additional meta-data associated with this component.  This field 
  79.      * will only be filled in if you set the 
  80.      * {@link PackageManager#GET_META_DATA} flag when requesting the info. 
  81.      */  
  82.     public Bundle metaData;  
  83.       
  84.     public PackageItemInfo() {  
  85.     }  
  86.   
  87.     public PackageItemInfo(PackageItemInfo orig) {  
  88.         name = orig.name;  
  89.         if (name != null) name = name.trim();  
  90.         packageName = orig.packageName;  
  91.         labelRes = orig.labelRes;  
  92.         nonLocalizedLabel = orig.nonLocalizedLabel;  
  93.         if (nonLocalizedLabel != null) nonLocalizedLabel = nonLocalizedLabel.toString().trim();  
  94.         icon = orig.icon;  
  95.         logo = orig.logo;  
  96.         metaData = orig.metaData;  
  97.     }  
  98.   
  99.     /** 
  100.      * Retrieve the current textual label associated with this item.  This 
  101.      * will call back on the given PackageManager to load the label from 
  102.      * the application. 
  103.      *  
  104.      * @param pm A PackageManager from which the label can be loaded; usually 
  105.      * the PackageManager from which you originally retrieved this item. 
  106.      *  
  107.      * @return Returns a CharSequence containing the item's label.  If the 
  108.      * item does not have a label, its name is returned. 
  109.      */  
  110.     public CharSequence loadLabel(PackageManager pm) {  
  111.         if (nonLocalizedLabel != null) {  
  112.             return nonLocalizedLabel;  
  113.         }  
  114.         if (labelRes != 0) {  
  115.             CharSequence label = pm.getText(packageName, labelRes, getApplicationInfo());  
  116.             if (label != null) {  
  117.                 return label.toString().trim();  
  118.             }  
  119.         }  
  120.         if (name != null) {  
  121.             return name;  
  122.         }  
  123.         return packageName;  
  124.     }  
  125.       
  126.     /** 
  127.      * Retrieve the current graphical icon associated with this item.  This 
  128.      * will call back on the given PackageManager to load the icon from 
  129.      * the application. 
  130.      *  
  131.      * @param pm A PackageManager from which the icon can be loaded; usually 
  132.      * the PackageManager from which you originally retrieved this item. 
  133.      *  
  134.      * @return Returns a Drawable containing the item's icon.  If the 
  135.      * item does not have an icon, the item's default icon is returned 
  136.      * such as the default activity icon. 
  137.      */  
  138.     public Drawable loadIcon(PackageManager pm) {  
  139.         if (icon != 0) {  
  140.             Drawable dr = pm.getDrawable(packageName, icon, getApplicationInfo());  
  141.             if (dr != null) {  
  142.                 return dr;  
  143.             }  
  144.         }  
  145.         return loadDefaultIcon(pm);  
  146.     }  
  147.       
  148.     /** 
  149.      * Retrieve the default graphical icon associated with this item. 
  150.      *  
  151.      * @param pm A PackageManager from which the icon can be loaded; usually 
  152.      * the PackageManager from which you originally retrieved this item. 
  153.      *  
  154.      * @return Returns a Drawable containing the item's default icon 
  155.      * such as the default activity icon. 
  156.      *  
  157.      * @hide 
  158.      */  
  159.     protected Drawable loadDefaultIcon(PackageManager pm) {  
  160.         return pm.getDefaultActivityIcon();  
  161.     }  
  162.       
  163.     /** 
  164.      * Retrieve the current graphical logo associated with this item. This 
  165.      * will call back on the given PackageManager to load the logo from 
  166.      * the application. 
  167.      *  
  168.      * @param pm A PackageManager from which the logo can be loaded; usually 
  169.      * the PackageManager from which you originally retrieved this item. 
  170.      *  
  171.      * @return Returns a Drawable containing the item's logo. If the item 
  172.      * does not have a logo, this method will return null. 
  173.      */  
  174.     public Drawable loadLogo(PackageManager pm) {  
  175.         if (logo != 0) {  
  176.             Drawable d = pm.getDrawable(packageName, logo, getApplicationInfo());  
  177.             if (d != null) {  
  178.                 return d;  
  179.             }  
  180.         }  
  181.         return loadDefaultLogo(pm);  
  182.     }  
  183.       
  184.     /** 
  185.      * Retrieve the default graphical logo associated with this item. 
  186.      *  
  187.      * @param pm A PackageManager from which the logo can be loaded; usually 
  188.      * the PackageManager from which you originally retrieved this item. 
  189.      *  
  190.      * @return Returns a Drawable containing the item's default logo 
  191.      * or null if no default logo is available. 
  192.      *  
  193.      * @hide 
  194.      */  
  195.     protected Drawable loadDefaultLogo(PackageManager pm) {  
  196.         return null;  
  197.     }  
  198.       
  199.     /** 
  200.      * Load an XML resource attached to the meta-data of this item.  This will 
  201.      * retrieved the name meta-data entry, and if defined call back on the 
  202.      * given PackageManager to load its XML file from the application. 
  203.      *  
  204.      * @param pm A PackageManager from which the XML can be loaded; usually 
  205.      * the PackageManager from which you originally retrieved this item. 
  206.      * @param name Name of the meta-date you would like to load. 
  207.      *  
  208.      * @return Returns an XmlPullParser you can use to parse the XML file 
  209.      * assigned as the given meta-data.  If the meta-data name is not defined 
  210.      * or the XML resource could not be found, null is returned. 
  211.      */  
  212.     public XmlResourceParser loadXmlMetaData(PackageManager pm, String name) {  
  213.         if (metaData != null) {  
  214.             int resid = metaData.getInt(name);  
  215.             if (resid != 0) {  
  216.                 return pm.getXml(packageName, resid, getApplicationInfo());  
  217.             }  
  218.         }  
  219.         return null;  
  220.     }  
  221.   
  222.     protected void dumpFront(Printer pw, String prefix) {  
  223.         if (name != null) {  
  224.             pw.println(prefix + "name=" + name);  
  225.         }  
  226.         pw.println(prefix + "packageName=" + packageName);  
  227.         if (labelRes != 0 || nonLocalizedLabel != null || icon != 0) {  
  228.             pw.println(prefix + "labelRes=0x" + Integer.toHexString(labelRes)  
  229.                     + " nonLocalizedLabel=" + nonLocalizedLabel  
  230.                     + " icon=0x" + Integer.toHexString(icon));  
  231.         }  
  232.     }  
  233.       
  234.     protected void dumpBack(Printer pw, String prefix) {  
  235.         // no back here  
  236.     }  
  237.       
  238.     public void writeToParcel(Parcel dest, int parcelableFlags) {  
  239.         dest.writeString(name);  
  240.         dest.writeString(packageName);  
  241.         dest.writeInt(labelRes);  
  242.         TextUtils.writeToParcel(nonLocalizedLabel, dest, parcelableFlags);  
  243.         dest.writeInt(icon);  
  244.         dest.writeInt(logo);  
  245.         dest.writeBundle(metaData);  
  246.     }  
  247.       
  248.     protected PackageItemInfo(Parcel source) {  
  249.         name = source.readString();  
  250.         packageName = source.readString();  
  251.         labelRes = source.readInt();  
  252.         nonLocalizedLabel  
  253.                 = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);  
  254.         icon = source.readInt();  
  255.         logo = source.readInt();  
  256.         metaData = source.readBundle();  
  257.     }  
  258.   
  259.     /** 
  260.      * Get the ApplicationInfo for the application to which this item belongs, 
  261.      * if available, otherwise returns null. 
  262.      *  
  263.      * @return Returns the ApplicationInfo of this item, or null if not known. 
  264.      *  
  265.      * @hide 
  266.      */  
  267.     protected ApplicationInfo getApplicationInfo() {  
  268.         return null;  
  269.     }  
  270.   
  271.     public static class DisplayNameComparator  
  272.             implements Comparator<PackageItemInfo> {  
  273.         public DisplayNameComparator(PackageManager pm) {  
  274.             mPM = pm;  
  275.         }  
  276.   
  277.         public final int compare(PackageItemInfo aa, PackageItemInfo ab) {  
  278.             CharSequence  sa = aa.loadLabel(mPM);  
  279.             if (sa == null) sa = aa.name;  
  280.             CharSequence  sb = ab.loadLabel(mPM);  
  281.             if (sb == null) sb = ab.name;  
  282.             return sCollator.compare(sa.toString(), sb.toString());  
  283.         }  
  284.   
  285.         private final Collator   sCollator = Collator.getInstance();  
  286.         private PackageManager   mPM;  
  287.     }  
  288. }  
示例:

AnroidManifest.xml如下:

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     package="com.getmanifestdemo"  
  4.     android:versionCode="1"  
  5.     android:versionName="3.2.1.32768" >  
  6.   
  7.     <uses-sdk  
  8.         android:minSdkVersion="8"  
  9.         android:targetSdkVersion="17" />  
  10.   
  11.     <application  
  12.         android:allowBackup="true"  
  13.         android:icon="@drawable/ic_launcher"  
  14.         android:label="@string/app_name"  
  15.         android:theme="@style/AppTheme" >  
  16.         <meta-data  
  17.             android:name="channel"  
  18.             android:value="$(CHANNEL)" />  
  19.   
  20.         <activity  
  21.             android:name="com.getmanifestdemo.MainActivity"  
  22.             android:label="@string/app_name" >  
  23.             <intent-filter>  
  24.                 <action android:name="android.intent.action.MAIN" />  
  25.   
  26.                 <category android:name="android.intent.category.LAUNCHER" />  
  27.             </intent-filter>  
  28.         </activity>  
  29.     </application>  
  30.   
  31. </manifest>  

解析代码:

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. PackageManager pkgmanager = mContext.getPackageManager();  
  2.         try {  
  3.             String packageName = mContext.getPackageName();  
  4.             PackageInfo packageInfo = pkgmanager.getPackageInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);  
  5.             String versionName = packageInfo.versionName;  
  6.             Log.v("YAN", "versionName:" + versionName);  
  7.             ApplicationInfo application = pkgmanager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);  
  8.             Bundle metaData = application.metaData;  
  9.             String channel = metaData.getString("IFLYTEK_CHANNEL");  
  10.             Log.v("YAN", "channel name:" + channel);  
  11.               
  12.         } catch (NameNotFoundException e) {  
  13.             Log.v("YAN", "channel name exception:" + e.getMessage());  
  14.             e.printStackTrace();  
  15.         }  
Android从零开始-AndroidManifest.xml解析 Android开发从零开始,提供从环境搭建到Android入门的基本教程,旨在引导广大开发者入门,关于Android深入细节等各种技术的学习,还请参考Android官方教程和demo。 官方网站:https://developer.android.com/ Android是一个庞大系统,不仅可以作为手机开发,在车载、电视等都能很好的兼容,无论针对哪种设备开发,核心不变,学好基础才是最重要的。 该章节重点讲解Android配置文件Manifest的各个标签,主要参考google开发者网站关于配置文件的讲 阅读详情

相关推荐

4相5线步进电机驱动原理

步进电机驱动

while(1) 3万+

The activity ‘MainTwoActivity‘ is not declared in AndroidManifest.xml

解决办法 打开AndroidMainfest.xml 复制MainActivity类的模板复制粘贴在它的下面,然后把文件名改成自定义即可

stormzhuo的博客 5788

JeecgBoot漏洞利用工具解析:一键getshell原理与安全加固实践

在应用安全领域,远程代码执行(RCE)和文件上传漏洞是Web系统面临的高危威胁,其核心原理在于对用户输入的控制不足或安全校验缺失。攻击者通过构造恶意请求,可绕过系统边界,在服务器上执行任意命令或上传恶意文件,从而获取系统控制权。这类漏洞的技术价值在于揭示了应用层安全防护的薄弱环节,其利用方式自动化、集成化趋势明显,极大地提升了攻击效率。在低代码开发平台等快速构建的业务系统中,此类风险尤为突出。应用场景广泛覆盖安全测试、渗透评估与应急响应。本文聚焦于JeecgBoot平台的历史高危漏洞,深入解析其SQL注入、

weixin_30787531的博客 555

安装 Android Studio 2024.1.1.6(Koala SDK35)和过程问题解决

记录更新Android Studio版本及适配Android V应用配置的一些过程问题。

。 6995

腾讯滑块验证码collect参数逆向与JSVMP对抗实战

本文深入解析腾讯滑块验证码collect参数的逆向过程与JSVMP虚拟机对抗技术。通过详细的环境搭建、抓包分析和JSVMP逆向技巧,揭示collect参数的生成逻辑与加密流程,并提供完整的模拟实现方案和常见问题排查方法,助力开发者突破腾讯天御验证码的防护机制。

weixin_29009501的博客 1602

Arch Linux 命令大全,值得收藏!

Arch Linux 是一款轻量级、高度可定制的 Linux 发行版,以其简洁和强大的特性深受高级用户喜爱。但对于新手来说,完全掌握 Arch Linux 的操作需要时间和实践。本文将为您详细介绍常用的 Arch Linux 命令,涵盖系统管理、文件操作、用户管理、软件安装与管理、网络配置和磁盘管理等内容,帮助您更高效地使用 Arch Linux。

网络技术联盟站 980

Android开发——Package is not specified in the manifest file

前言 在开发当中难免不会遇到代码重构,我这次在开发中遇到的是Package is not specified in the manifest file,这是表示清单文件中没有指定包。 复现这个错误的出现过程 这个错误是我在xml文件当中需要Extract dimension resource时候出现的。 解决的办法 很尴尬的事情出现,原来我删除之前没有用的资源的时候,不小心将Andr...

裕博的博客 2040

智能车图像处理21-进阶篇13--正入十字补线2

这篇文章主要的正入十字补线与1基本相同,主要防止图像中双十字的问题。

taiyuezyh的博客 2040

android manifest解析

Manifest如何解析的? 1)系统启动的时候,PackagedManageService读取所有程序的Manifest.xml信息,写入系统共享内存,相当于有一张所有应用程序的信息表 2)应用程序启动时候,Launcher进行系统级判断,比如最小SDK等 3)四大组件在需要的时候实例化...

iteye_19747的博客 155

AI预测彩票,使用chatgpt和lstm神经网络(文末附源码)

AI预测彩票,使用chatgpt和lstm神经网络(文末有彩蛋)

14 年后端老兵,专注工程实战与银河麒麟信创运维。把每个真实生产事故,拆成能复现、能上线的保姆级教程。代码开源,评论区一起排错。 1万+

Open3D 球旋转算法(BPA)三维建模【2026最新版】

球旋转算法,博客长期更新,本文最新更新时间为:2026年4月11日。

点云侠的博客 37万+

Android学习 - ANDROID的MANIFEST.XML解析

每个做过Android应用的都知道Android的MANIFEST.XML很重要,每个Activity都必须在这里定义一下,但很少人知道这个xml中其他的文字字段是什么意思。这里只是我用过的给大家讲讲,错的请指出,我就是个凭感觉走的人。 android:allowTaskReparenting 是否允许activity更换从属的任务,比如从短信息任务切换到浏览器任务。 android:alw

wolflz的专栏 530

别再被 SerialPort 坑了!C# 串口通信的 3 大隐形陷阱与工业级解决方案

NET的SerialPort类更适合实验室调试,而非工业现场——它的设计目标是“能用”,而非“稳定”。工业级串口通信的核心,是在SerialPort基础上构建一层“防护壳”,用主动轮询对抗事件失效,用硬件级操作解决缓冲区谎言,用原子性流程避免关闭死锁。本文提供的类已在30+工业项目中验证(包括汽车生产线、智能仓储、环境监测),可直接替换原生SerialPort,解决90%以上的“玄学问题”。记住:工业场景的“稳定”,从来都不是靠运气,而是靠对每个细节的偏执把控。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 754

Android 的manifest解析,深度好文

如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。一定会认真查询,修正不足。最后针对Android程序员,我这边给大家整理了一些资料,包括不限于高级UI、性能优化、移动架构师、NDK、混合式开发(ReactNative+Weex)微信小程序、Flutter等全方面的Android进阶实践技术;希望能帮助到大家,也节省大家在网上搜索资料的时间来学习,也可以分享动态给身边好友一起学习!如果你看到了这里,觉得文章写得不错就给个赞呗?如果你觉得那里值得改进的,请给我留言。

时间与思念 1129

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

Android源码解析之(十二)-->系统启动并解析Manifest的流程

最近有同学问我关于Manifest何时被系统解析的问题,正好也分析到这一块了,索性这一章就讲解一下android系统何时解析Manifest吧,这里的Manifest指的是android安装文件apk中的androidManifest.xml文件是何时被解析的。 大家应该都知道,Android系统启动之后,我们就可以在一个应用中打开另一个从未打开过的应用,或者是在一个应用中发送广播,如果另外一个

一片枫叶的专栏 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android Manifest内容解析

Manifest文件分三个部分:全局信息配置、组件信息、权限配置 1.全局信息配置 1)应用的包名以及版本信息的管理 2)控制Android版本信息(可以支持的最低版本、你期望的系统版本) 2.组件信息 由application这个大标签包裹。该标签的属性可以设置图标、标题、主题样式。 里面可以包含activity、service、conten...

weixin_34326558的博客 243

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Android Manifest 标签解析

每个应用项目必须在项目源设置的根目录中加入 AndroidManifest.xml 文件(且必须使用此名称)。 清单文件会向 Android 构建工具、Android 操作系统和 Google Play 描述应用的基本信息。

特立独行的博客 2224

ANDROID的MANIFEST.XML文件字段解析

ANDROID的MANIFEST.XML文件字段解析 Android:allowTaskReparenting 是否允许activity更换从属的任务,比如从短信息任务 切换到浏览器任务。 android:alwaysRetainTaskState 是否保留状态不变, 比如切换回home, 再从新打开, activity处于最后的状态 android:clearTaskO...

mobile payment development 142

深入理解 Android Manifest 合并规则:解析 cw-omnibus 的 Manifest/Merger 示例

本篇技术指南以 cw-omnibus(*The Busy Coder's Guide to Android Development* 一书的配套示例仓库)中的 [Manifest/Merger](https://link.gitcode.com/i/53ce5f110233bdafa161350e7a9867ce) 示例为切入点,系统讲解 Android Gradle Plugin(AGP)清单合

gitblog_00041的博客 750

5分钟看完Android Manifest 清单文件 详细解析

一、关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件。它位于整个项目的根目录,描述了package中暴露的组件(activities, services, 等等),他们各自的实现类,各种能被处理的数据和启动位置。 除了能声明程序中的Activities, ContentProviders, Services, 和In

jys1115的专栏 1790

Android Manifest.xml文件解析

一、关于AndroidManifest.xml AndroidManifest.xml是每个android程序中必须的文件。它位于整个项目的根目录,描述了package中暴露的组件(activities, services, 等等),他们各自的实现类,各种能被处理的数据和启动位置。除了能声明程序中的Activities, ContentProviders, Services, 和Intent

海燕王子的博客 392
上一篇: Android应用启动过程浅析
下一篇: android 中Activity在程序运行过程中进入全屏和退出全屏
cding1818
博客等级 码龄17年 963粉丝 154原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值