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();
}
}
}
Wat am i dng wrong here pls help with some code if possible.Thanx!!!