本文介绍了我怎样才能得到这是其他包装第二轮活动的包叫什么名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里我的情况下,一个应用程序调用一个服务,该服务将inturn开始的活动。在这里我的问题是让应用程序包,其中调用该服务。

here in my case, a app invokes a service and the service will inturn starts an activity. My problem here is to get the app package which invokes that service.

任何人可以帮助我解决这个?

Can anybody help me to solve this ?

推荐答案

我从android源码发现这个直接和它的作品罚款:)

I found this directly from android source and it works fine :)

final ActivityManager am = (ActivityManager)
                getSystemService(Context.ACTIVITY_SERVICE);

        final List<ActivityManager.RecentTaskInfo> recentTasks =
                am.getRecentTasks(3, ActivityManager.RECENT_IGNORE_UNAVAILABLE);
        for (int i = 0, index = 0; i < 3 && (index < 3); ++i) {
            final ActivityManager.RecentTaskInfo recentInfo = recentTasks.get(i);

            Intent intent = new Intent( recentInfo.baseIntent);
            if ( recentInfo.origActivity != null) {
                intent.setComponent( recentInfo.origActivity);
            }

            final PackageManager pm = getPackageManager();
            final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
            final ActivityInfo info = resolveInfo.activityInfo;
            final String title = info.loadLabel(pm).toString();

            Log.d("hello","  "+title+" "+info.packageName);
           final ImageView iv = (ImageView)findViewById(R.id.imageView1);
           iv.setImageDrawable(info.loadIcon(pm));
                ++index;
            }

这篇关于我怎样才能得到这是其他包装第二轮活动的包叫什么名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 15:46