다른 응용 프로그램에서 만든 바로 가기 브로드캐스트를 수신합니다.
2967 단어 BroadcastLauncherextraIntent
public class InstallShortcutReceiver extends BroadcastReceiver {
private static final String ACTION_INSTALL_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ACTION_INSTALL_SHORTCUT)) {
String name = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
Intent extraIntent = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (name == null) {
try {
PackageManager pm = context.getPackageManager();
ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
name = info.loadLabel(pm).toString();
} catch (PackageManager.NameNotFoundException nnfe) {
return;
}
}
ComponentName component = null;
Bitmap bitmap = null;
ShortcutIconResource iconResource = null;
Parcelable bitmapParcelable = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
if (bitmapParcelable != null && bitmapParcelable instanceof Bitmap) {
bitmap = (Bitmap) bitmapParcelable;
} else {
Parcelable extra = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
if (extra != null && extra instanceof ShortcutIconResource) {
try {
iconResource = (ShortcutIconResource) extra;
PackageManager packageManager = context.getPackageManager();
Resources resources = packageManager.getResourcesForApplication(iconResource.packageName);
int id = resources.getIdentifier(iconResource.resourceName, null, null);
Drawable drawable = resources.getDrawable(id);
bitmap = Util.drawableToBitmap(drawable);
} catch (Exception e) {
// TODO: handle exception
}
}
}
if (extraIntent == null) {
return;
} else {
if (extraIntent.getAction() == null) {
extraIntent.setAction(Intent.ACTION_VIEW);
} else if (extraIntent.getAction().equals(Intent.ACTION_MAIN) && extraIntent.getCategories() != null
&& extraIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
extraIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
}
component = extraIntent.getComponent();
if (component == null) {
if (iconResource != null) {
component = new ComponentName(iconResource.packageName, iconResource.resourceName);
} else {
component = new ComponentName("com.joy.other", "com.joy.otherActivity");
}
}
TrinityButtonInfo buttonInfo = new TrinityButtonInfo(new ButtonMetaData());
buttonInfo.mComponentName = component;
buttonInfo.mTitle = name;
buttonInfo.mBitmap = BitmapHelper.createIconBitmap(bitmap, LauncherApplication.mContext, null, true);
buttonInfo.mIntent = extraIntent;
buttonInfo.mShortcutTitle = name;
buttonInfo.mShortcutBitmap = bitmap;
addButtonsToCurrentHomePage(buttonInfo);
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
launcher 수정 - launcher 화면 수 수정우선, Launcher에서.java 코드 중 이 두 단락을 수정하다 그리고 항목을 선택하고Search>File를 선택하고defaultscreen을 입력하여Selected Resources를 선택하여 검색을 클릭하면 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.