gpt4 book ai didi

android - 从 ListView 共享特定的 apk

转载 作者:行者123 更新时间:2023-11-30 01:42:55 26 4
gpt4 key购买 nike

嘿伙计们,我有一个 ListView ,其中包含已安装的 apk 我想分享用户点击的特定 apk。当我点击分享时我有一些代码“通过蓝牙分享”弹出但它没有收到我的其他设备。

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();
}

}

}

我哪里错了,如果可能的话请帮助一些代码。谢谢!!!

最佳答案

您不能在 inListItemClick 中尝试此操作,以防情况 0 而不是您的代码尝试此操作。

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"));

关于android - 从 ListView 共享特定的 apk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34193080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com