搜尋此網誌

2016年4月18日 星期一

【Android】無題 純紀錄(ComponentName )

public ComponentName (String pkg, String cls)

Added in API level 1
Create a new component identifier.
Parameters
pkgString: The name of the package that the component exists in. Can not be null.
clsString: The name of the class inside of pkg that implements the component. Can not be null.

public ComponentName (Context pkg, String cls)

Added in API level 1
Create a new component identifier from a Context and class name.
Parameters
pkgContext: A Context for the package implementing the component, from which the actual package name will be retrieved.
clsString: The name of the class inside of pkg that implements the component.

public ComponentName (Context pkg, Class<?> cls)

Added in API level 1
Create a new component identifier from a Context and Class object.
Parameters
pkgContext: A Context for the package implementing the component, from which the actual package name will be retrieved.
clsClass: The Class object of the desired component, from which the actual class name will be retrieved.

ComponentName c = new ComponentName(resolveInfo.activityInfo.packagename,
resolveInfo.activityInfo.name);
Intent i = new Intent();
i.setComponent(c);
startActivity(i);


REF:
http://blog.csdn.net/feng88724/article/details/6198446
http://chihweiwu.blogspot.tw/2013/02/androidandroid.html

通過 PackageInfo  獲取具體信息方法:

包名獲取方法:packageInfo.packageName
icon獲取獲取方法:packageManager.getApplicationIcon(applicationInfo)
應用名稱獲取方法:packageManager.getApplicationLabel(applicationInfo)
使用權限獲取方法:packageManager.getPackageInfo(packageName,PackageManager.GET_PERMISSIONS)
.requestedPermissions

通過 ResolveInfo 獲取具體信息方法:

包名獲取方法:resolve.activityInfo.packageName
icon獲取獲取方法:resolve.loadIcon(packageManager)
應用名稱獲取方法:resolve.loadLabel(packageManager).toString()

REF:
http://www.cnblogs.com/yydcdut/p/4287077.html

public boolean isIntentAvailable(Context context, String action) {  
    final PackageManager packageManager = context.getPackageManager();  
    final Intent intent = new Intent(action);  
    List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);  
   if (resolveInfo.size() > 0) {  
        return true;  
    }  
   return false;  
}
一般APP的manifest裡面要設置為launcher的activity總是要設置intent-filter:
<intent-filter>  
                <action android:name="android.intent.action.MAIN" />  
                <category android:name="android.intent.category.LAUNCHER" />  
</intent-filter>
可以通過queryIntentActivities來獲得有哪些launcher:
private void loadApps() {           
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);           
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);             
        mApps = getPackageManager().queryIntentActivities(mainIntent, 0);       
    }

public static final int COMPONENT_ENABLED_STATE_DEFAULT

Added in API level 1
Flag for setApplicationEnabledSetting(String, int, int) and setComponentEnabledSetting(ComponentName, int, int): This component or application is in its default enabled state (as specified in its manifest).
Constant Value: 0 (0x00000000)

public static final int MATCH_ALL

Added in API level 23
Querying flag: if set and if the platform is doing any filtering of the results, then the filtering will not happen. This is a synonym for saying that all results should be returned.
Constant Value: 131072 (0x00020000)

public static final int MATCH_DEFAULT_ONLY

Added in API level 1
Resolution and querying flag: if set, only filters that support the CATEGORY_DEFAULT will be considered for matching. This is a synonym for including the CATEGORY_DEFAULT in your supplied Intent.
Constant Value: 65536 (0x00010000)

UsageStats

Added in API level 21
Public Methods
voidadd(UsageStats right)
Add the statistics from the right UsageStats to the left.
intdescribeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
longgetFirstTimeStamp()
Get the beginning of the time range this UsageStats represents, measured in milliseconds since the epoch.
longgetLastTimeStamp()
Get the end of the time range this UsageStats represents, measured in milliseconds since the epoch.
longgetLastTimeUsed()
Get the last time this package was used, measured in milliseconds since the epoch.
StringgetPackageName()
longgetTotalTimeInForeground()
Get the total time this package spent in the foreground, measured in milliseconds.
voidwriteToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.

沒有留言: