0

I am using this code to get the running proccesses

public class ProcessFragment extends ListFragment  {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getRunningProcess();
}
private void getRunningProcess() {
{
final ActivityManager manager = (ActivityManager)    getActivity().getSystemService(Context.ACTIVITY_SERVICE);
PackageManager pm;
List<RunningAppProcessInfo> runningProcesses = manager.getRunningAppProcesses();
if (runningProcesses != null && runningProcesses.size() > 0) {
setListAdapter(new ListAdapter(getActivity(), runningProcesses));   
    } else {    
Toast.makeText(getActivity().getApplicationContext(), "No application is running", Toast.LENGTH_LONG).show();
}
}

And here my adapter

public class ListAdapter extends ArrayAdapter<RunningAppProcessInfo> {
private final Context context;
private final List<RunningAppProcessInfo> values;
public ListAdapter(Context context, List<RunningAppProcessInfo> values) {
super(context, R.layout.process, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.process, parent, false);
TextView appName = (TextView) rowView.findViewById(R.id.appNameText);
appName.setText(values.get(position).processName);
return rowView;
}

}

I am getting the list of package's name .How to get the Application Name ??

Marya
  • 332
  • 2
  • 16

1 Answers1

2

For the most part, you should be able to use:

PackageManager pm = this.getPackageManager(); //assuming you're running from an activity
                                              //use a context otherwise
ApplicationInfo appInfo = pm.getApplicationInfo(values.get(position).processName, PackageManager.GET_META_DATA);
String appName = pm.getApplicationLabel(appInfo).toString();
appName.setText(appName);
Aleks G
  • 56,435
  • 29
  • 168
  • 265
  • @BirajZalavadia No mate, I actually wrote the code for OP, using the OP's context and setting. He can actually put this code into his app - and it will work. You on the other hand just pasted someone else's answer without even trying to adopt it to the original question. – Aleks G Apr 04 '14 at 09:46
  • I don't just copy and paste I test on my pc and then post it. However I downvoted you but now upvoted. thanx – Biraj Zalavadia Apr 04 '14 at 09:52