从共享列表视图具体APK [英] Sharing specific apk from listview

查看:182
本文介绍了从共享列表视图具体APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿家伙,我已经得到ListView控件包含安装apk的我想分享在其上的用户click.I已经得到了一些code当我点击份额的具体APK通过蓝牙共享弹出,但没有得到我的其他设备上收到的。

Hey guys i have got listview which contains installed apk's i want to share the specific apk on which the users click.I have got some code when i click on share "share via bluetooth "pops up but it didnt get received on my other device.

public class MainActivity extends ListActivity {
PackageManager packageManager;
List<ApplicationInfo> applist;
Listadapter listadapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    packageManager = getPackageManager();

    new LoadApplications().execute();

}

@Override
protected void onListItemClick(ListView l, View v, final int position, long id) {
    super.onListItemClick(l, v, position, id);

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle("Choose option")
            .setItems(R.array.options, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which) {

                        case 0:

                            ApplicationInfo app2 = applist.get(position);
                            Intent sharei=new Intent(Intent.ACTION_SEND);
                            Uri uri=Uri.parse("package:"+app2.packageName);
                            sharei.putExtra(Intent.EXTRA_STREAM,uri);
                            sharei.setType("application/vnd.android.package-archive");
                            startActivity(Intent.createChooser(sharei, "share"));
                            break;

                    }
                }
            });
    dialogBuilder.setCancelable(true).show();

 }

 private List<ApplicationInfo> checkForLaunchIntent(List<ApplicationInfo> list) {
    ArrayList<ApplicationInfo> applist = new ArrayList<>();

    for (ApplicationInfo info : list) {
        try {
            if  (packageManager.getLaunchIntentForPackage(info.packageName) != null) {
                applist.add(info);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return applist;
}

private class LoadApplications extends AsyncTask<Void, Void, Void> {
    private ProgressDialog progress = null;

    @Override
    protected Void doInBackground(Void... params) {
        applist = checkForLaunchIntent(packageManager.getInstalledApplications(PackageManager.GET_META_DATA));

        listadapter = new Listadapter(MainActivity.this, R.layout.list_item, applist);

        return null;
    }

    @Override
    protected void onPostExecute(Void aVoid) {
        setListAdapter(listadapter);
        progress.dismiss();
        super.onPostExecute(aVoid);

    }

    @Override
    protected void onPreExecute() {
        progress = ProgressDialog.show(MainActivity.this, null, "loading apps info,,,");
        super.onPreExecute();
    }

}

}

笏我在DNG错在这里请与一些code如果possible.Thanx!

Wat am i dng wrong here pls help with some code if possible.Thanx!!!

推荐答案

您不能在0的情况下,而不是你的code的尝试这种尝试这inListItemClick。

You cant try this in inListItemClick in case 0 instead of your code try this.

ApplicationInfo app2 = applist.get(position);
File srcFile = new File(app2.publicSourceDir);
Intent sharei=new Intent(Intent.ACTION_SEND);
sharei.setType("application/vnd.android.package-archive");
sharei.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(srcFile));   
startActivity(Intent.createChooser(sharei, "share"));

这篇关于从共享列表视图具体APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆