本文整理匯總了Java中android.content.ComponentName.getPackageName方法的典型用法代碼示例。如果您正苦於以下問題:Java ComponentName.getPackageName方法的具體用法?Java ComponentName.getPackageName怎麽用?Java ComponentName.getPackageName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.ComponentName
的用法示例。
在下文中一共展示了ComponentName.getPackageName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSuppressorCaption
import android.content.ComponentName; //導入方法依賴的package包/類
private String getSuppressorCaption(ComponentName suppressor) {
final PackageManager pm = mContext.getPackageManager();
try {
final ServiceInfo info = pm.getServiceInfo(suppressor, 0);
if (info != null) {
final CharSequence seq = info.loadLabel(pm);
if (seq != null) {
final String str = seq.toString().trim();
if (str.length() > 0) {
return str;
}
}
}
} catch (Throwable e) {
Log.w(TAG, "Error loading suppressor caption", e);
}
return suppressor.getPackageName();
}
示例2: handleInstallShortcutIntent
import android.content.ComponentName; //導入方法依賴的package包/類
private Intent handleInstallShortcutIntent(Intent intent) {
Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (shortcut != null) {
ComponentName component = shortcut.resolveActivity(VirtualCore.getPM());
if (component != null) {
String pkg = component.getPackageName();
Intent newShortcutIntent = new Intent();
newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
newShortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
newShortcutIntent.putExtra("_VA_|_intent_", shortcut);
newShortcutIntent.putExtra("_VA_|_uri_", shortcut.toUri(0));
newShortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
intent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);
Intent.ShortcutIconResource icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (icon != null && !TextUtils.equals(icon.packageName, getHostPkg())) {
try {
Resources resources = VirtualCore.get().getResources(pkg);
int resId = resources.getIdentifier(icon.resourceName, "drawable", pkg);
if (resId > 0) {
//noinspection deprecation
Drawable iconDrawable = resources.getDrawable(resId);
Bitmap newIcon = BitmapUtils.drawableToBitmap(iconDrawable);
if (newIcon != null) {
intent.removeExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newIcon);
}
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
return intent;
}
示例3: get
import android.content.ComponentName; //導入方法依賴的package包/類
/**
* - * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
* - * provided by the same package which is set to be global search activity.
* - * If widgetCategory is not supported, or no such widget is found, returns the first widget
* - * provided by the package.
* -
*/
public static AppWidgetProviderInfo get(Context context) {
SearchManager searchManager =
(SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
ComponentName searchComponent = searchManager.getGlobalSearchActivity();
if (searchComponent == null) return null;
String providerPkg = searchComponent.getPackageName();
AppWidgetProviderInfo defaultWidgetForSearchPackage = null;
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) {
if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
return info;
} else if (defaultWidgetForSearchPackage == null) {
defaultWidgetForSearchPackage = info;
}
}
}
return defaultWidgetForSearchPackage;
}
示例4: extractCallerAuthDomain
import android.content.ComponentName; //導入方法依賴的package包/類
private boolean extractCallerAuthDomain() {
ComponentName callingActivity = getCallingActivity();
if (callingActivity == null) {
Log.w(LOG_TAG, "No calling activity found for save call");
return false;
}
String callingPackage = callingActivity.getPackageName();
AuthenticationDomain authDomain =
AuthenticationDomain.fromPackageName(this, callingPackage);
if (null == authDomain) {
return false;
}
mCallerAuthDomain = authDomain;
return true;
}
示例5: verifyCaller
import android.content.ComponentName; //導入方法依賴的package包/類
private boolean verifyCaller() {
final ComponentName callingActivity = getCallingActivity();
if (callingActivity == null) {
Log.w(LOG_TAG, "No calling activity found for save call");
return false;
}
// TODO: a more complete implementation would need to expand this to the full set of
// affiliated apps and sites, though it is generally unusual for an app to save a
// credential for any authentication domain other than those it can directly identify as.
mCallingPackage = callingActivity.getPackageName();
mAuthDomainForApp = AuthenticationDomain.fromPackageName(this, mCallingPackage);
final AuthenticationDomain authDomain = mRequest.getCredential().getAuthenticationDomain();
if (!authDomain.equals(mAuthDomainForApp)) {
Log.w(LOG_TAG, "App " + mCallingPackage
+ " is not provably associated to authentication domain "
+ authDomain
+ " for the credential to be saved.");
return false;
}
return true;
}
示例6: getApp
import android.content.ComponentName; //導入方法依賴的package包/類
public AppLauncher getApp(ComponentName appname) {
String actvname = appname.getClassName();
String pkgname = appname.getPackageName();
AppLauncher appLauncher = null;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(APP_TABLE, appcolumns, ACTVNAME + "=? and " + PKGNAME + "=?", new String[]{actvname, pkgname}, null, null, null);
try {
if (cursor.moveToNext()) { //ACTVNAME, PKGNAME, LABEL, CATID
//pkgname = cursor.getString(1);
String label = cursor.getString(cursor.getColumnIndex(LABEL));
String catID = cursor.getString(cursor.getColumnIndex(CATID));
boolean widget = cursor.getShort(cursor.getColumnIndex(ISWIDGET)) == 1;
String customlabel = cursor.getString(cursor.getColumnIndex(CUSTOMLABEL));
// Log.d("LaunchDB", "getApp " + pkgname + " " + catID);
appLauncher = AppLauncher.createAppLauncher(actvname, pkgname, customlabel==null?label:customlabel, catID, widget);
}
} finally {
cursor.close();
}
return appLauncher;
}
示例7: schedule
import android.content.ComponentName; //導入方法依賴的package包/類
@Override
public int schedule(JobInfo job) throws RemoteException {
int vuid = VBinder.getCallingUid();
int id = job.getId();
ComponentName service = job.getService();
JobId jobId = new JobId(vuid, service.getPackageName(), id);
JobConfig config = mJobStore.get(jobId);
if (config == null) {
config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras());
mJobStore.put(jobId, config);
} else {
config.serviceName = service.getClassName();
config.extras = job.getExtras();
}
saveJobs();
mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId);
mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent);
return mScheduler.schedule(job);
}
示例8: isInSysInstallPage
import android.content.ComponentName; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
public static boolean isInSysInstallPage() {
String strTopPName = null;
Context context = ContextUtils.getApplicationContext();
if (context == null) {
return false;
}
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT > 20) {
final List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
if (processInfos != null && processInfos.size() > 0) {
for (ActivityManager.RunningAppProcessInfo processInfo : processInfos) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
if (ReflectUtils.getIntField(processInfo, "flags") == 4 && processInfo.pkgList.length == 1) {
strTopPName = processInfo.pkgList[0];
break;
}
}
}
}
} else {
//noinspection deprecation
List<ActivityManager.RunningTaskInfo> runningTaskInfos = am.getRunningTasks(1);
if (runningTaskInfos != null && !runningTaskInfos.isEmpty()) {
ComponentName componentName = runningTaskInfos.get(0).topActivity;
if (componentName != null && componentName.getPackageName() != null) {
strTopPName = componentName.getPackageName();
}
}
}
logPrint("isInSysInstallPage : strTopPName=" + strTopPName);
return MyAccessibility.packages[0].equalsIgnoreCase(strTopPName);
}
示例9: reStart
import android.content.ComponentName; //導入方法依賴的package包/類
/**
* 重新啟動
*/
public void reStart()
{
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
AlarmManager mgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
List<RunningTaskInfo> taskInfos = am.getRunningTasks(Integer.MAX_VALUE);
RunningTaskInfo taskInfo = null;
ComponentName baseActivity = null;
String pkgName = null;
for (int i = 0, len = taskInfos.size(); i < len; i++)
{
taskInfo = taskInfos.get(i);
baseActivity = taskInfo.baseActivity;
pkgName = baseActivity.getPackageName();
if (pkgName.equalsIgnoreCase(mContext.getPackageName()))
{
ComponentName topActivity = taskInfo.topActivity;
if (!topActivity.getClassName().equalsIgnoreCase(baseActivity.getClassName()))
{
Intent intent = new Intent();
intent.setClassName(mContext, baseActivity.getClassName());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
mgr.set(AlarmManager.RTC, System.currentTimeMillis(), pendingIntent);
}
return;
}
}
}
示例10: handleBadger
import android.content.ComponentName; //導入方法依賴的package包/類
@Override
public BadgerInfo handleBadger(Intent intent) {
BadgerInfo info = new BadgerInfo();
String componentName = intent.getStringExtra(getComponentKey());
ComponentName component = ComponentName.unflattenFromString(componentName);
if (component != null) {
info.packageName = component.getPackageName();
info.className = component.getClassName();
info.badgerCount = intent.getIntExtra(getCountKey(), 0);
return info;
}
return null;
}
示例11: getCallingPackageName
import android.content.ComponentName; //導入方法依賴的package包/類
@Nullable
private String getCallingPackageName() {
ComponentName componentName = getActivity().getCallingActivity();
String packageName = null;
if (componentName != null) {
packageName = componentName.getPackageName();
}
return packageName;
}
示例12: currentAppPackageNameOnForeground
import android.content.ComponentName; //導入方法依賴的package包/類
/**
* 慎重使用此函數<br/>
* GET_TASK was deprecated in API level 21. No longer enforced
*/
public static String currentAppPackageNameOnForeground(final Context context) {
try {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
return topActivity.getPackageName();
}
}catch (Exception ex){
ex.printStackTrace();
}
return "";
}
示例13: openURL
import android.content.ComponentName; //導入方法依賴的package包/類
/**
* Starts a corresponding external activity for the given URL.
*
* For example, if the URL is "https://www.facebook.com", the system browser will be opened,
* or the "choose application" dialog will be shown.
*
* @param url the URL to open
*/
@ReactMethod
public void openURL(String url, Promise promise) {
if (url == null || url.isEmpty()) {
promise.reject(new JSApplicationIllegalArgumentException("Invalid URL: " + url));
return;
}
try {
Activity currentActivity = getCurrentActivity();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
String selfPackageName = getReactApplicationContext().getPackageName();
ComponentName componentName = intent.resolveActivity(
getReactApplicationContext().getPackageManager());
String otherPackageName = (componentName != null ? componentName.getPackageName() : "");
// If there is no currentActivity or we are launching to a different package we need to set
// the FLAG_ACTIVITY_NEW_TASK flag
if (currentActivity == null || !selfPackageName.equals(otherPackageName)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
if (currentActivity != null) {
currentActivity.startActivity(intent);
} else {
getReactApplicationContext().startActivity(intent);
}
promise.resolve(true);
} catch (Exception e) {
promise.reject(new JSApplicationIllegalArgumentException(
"Could not open URL '" + url + "': " + e.getMessage()));
}
}
示例14: isRunningForeground
import android.content.ComponentName; //導入方法依賴的package包/類
private boolean isRunningForeground(Context context)
{
ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
String currentPackageName = cn.getPackageName();
if(!TextUtils.isEmpty(currentPackageName) && currentPackageName.equals(context.getPackageName()))
{
return true ;
}
return false ;
}
示例15: getParentActivityIntent
import android.content.ComponentName; //導入方法依賴的package包/類
public static Intent getParentActivityIntent(Context context, ComponentName componentName) throws NameNotFoundException {
String parentActivity = getParentActivityName(context, componentName);
if (parentActivity == null) {
return null;
}
ComponentName target = new ComponentName(componentName.getPackageName(), parentActivity);
return getParentActivityName(context, target) == null ? IntentCompat.makeMainActivity(target) : new Intent().setComponent(target);
}