嘿伙计们我有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();
}
}
}
Wat am i dng wrong this pls如果可能请帮助一些代码。谢谢!!!
答案 0 :(得分:1)
你无法在inListItemClick中尝试这种情况而不是代码尝试这个。
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"));