如何从Packageinfo启动应用程序

时间:2015-03-30 05:55:43

标签: android

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.first_activity, container, false);
    packageManager = getActivity().getPackageManager();
    // / see this is use of context./.. can also use getActivity()
    List<PackageInfo> packageList = packageManager
            .getInstalledPackages(PackageManager.GET_PERMISSIONS);
    packageList1 = new ArrayList<PackageInfo>();
    for (PackageInfo pi : packageList) {
        boolean b = isSystemPackage(pi);
        if (!b) {
            packageList1.add(pi);
        }
    }
    apkList = (GridView) v.findViewById(R.id.gridView1);
    apkList.setAdapter(new GridAdapter(getActivity(), packageList1,
            packageManager));
    System.out.println("View " + v);
    apkList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            System.out.println("parent "
                    + parent.getItemAtPosition(position));
            Intent launchIntent = getActivity().getPackageManager()
                    .getLaunchIntentForPackage(
                            parent.getItemAtPosition(position).toString());
            startActivity(launchIntent);
            }
    });
    return v;
}

日志:

  

03-30 11:14:43.768:I / System.out(3236):parent PackageInfo {15e87b8f com.flipkart.android}

     

03-30 11:14:43.788:I / System.out(3236):launchIntent null

我在OnItemClickListener的父级中有PackageInfo,如何使用&#34; PackageInfo&#34;来启动活动。请看日志。提前谢谢。

0 个答案:

没有答案