Java 如何从我的launcher应用程序的另一个应用程序中获取高dpi活动图标?
我想从设备上的另一个应用程序中获取一个具有最高分辨率的活动图标,但我不知道如何实现 在我的应用程序中,我可以从设备上可用的所有活动列表中选择一个活动,相应的TIG意图将返回到onActivityResult。在那里,我可以得到如下活动图标:Java 如何从我的launcher应用程序的另一个应用程序中获取高dpi活动图标?,java,android,android-intent,android-activity,icons,Java,Android,Android Intent,Android Activity,Icons,我想从设备上的另一个应用程序中获取一个具有最高分辨率的活动图标,但我不知道如何实现 在我的应用程序中,我可以从设备上可用的所有活动列表中选择一个活动,相应的TIG意图将返回到onActivityResult。在那里,我可以得到如下活动图标: Drawable icon = null; ComponentName componentName = intent.getComponent(); String packageName = componentName.getPack
Drawable icon = null;
ComponentName componentName = intent.getComponent();
String packageName = componentName.getPackageName();
PackageManager pm = this.getPackageManager();
icon = pm.getActivityIcon(intent);
PackageInfo pi = pm.getPackageInfo(packageName, 0);
Context otherAppCtx = this.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);
int displayMetrics[] = { DisplayMetrics.DENSITY_TV, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_XXXHIGH };
for (int displayMetric : displayMetrics)
{
try
{
Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon, displayMetric);
if (d != null)
{
icon = d;
}
}
catch (Resources.NotFoundException e)
{
continue;
}
}
然后,我可以获得最高分辨率的应用程序图标,如下所示:
Drawable icon = null;
ComponentName componentName = intent.getComponent();
String packageName = componentName.getPackageName();
PackageManager pm = this.getPackageManager();
icon = pm.getActivityIcon(intent);
PackageInfo pi = pm.getPackageInfo(packageName, 0);
Context otherAppCtx = this.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);
int displayMetrics[] = { DisplayMetrics.DENSITY_TV, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_XXXHIGH };
for (int displayMetric : displayMetrics)
{
try
{
Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon, displayMetric);
if (d != null)
{
icon = d;
}
}
catch (Resources.NotFoundException e)
{
continue;
}
}
这很好,但我想要的是活动图标,而不是分辨率最高的应用程序图标。有人知道怎么做吗
提前谢谢 您使用它是正确的,您只需要使用
ActivityInfo
而不是PackageInfo
。e、 g.如果您有:
Drawable icon = null;
ComponentName componentName = intent.getComponent();
String packageName = componentName.getPackageName();
PackageManager pm = this.getPackageManager();
icon = pm.getActivityIcon(intent);
获取图标资源(如果已设置),而不是获取可绘制资源:
然后,您应该能够使用第二种方法通过密度来解决问题。通过活动图标,您指的是应用程序图标?这个问题似乎离题了,因为它涉及侵犯版权。@tyczj无活动图标,例如:安卓上的contacs应用程序有多个活动。其中一个是电话活动,它有一个电话符号(我在发布代码的第一部分得到)。但是应用程序图标是“人”图标(我在代码的第二部分得到了这个图标)。@Dan S:我不这么认为。有许多应用程序在手机上启动其他活动,并使用它们的图标。想不到他们都是非法的!我不想偷这些图标或其他东西。@Dan S:是的,我做了一个发射器,希望有最好的质量,使它看起来尽可能好。我还可以放大尺寸……希望这能让事情变得足够清楚;)我觉得我很接近,但是……天哪,那很容易;)非常感谢您的解释,也非常感谢您清晰准确的解释!干杯!;)@KCopock:没有问题,只有情况;)