我尝试在我的应用程序中调用另一个应用程序来共享数据。但是当其他应用程序打开时,突然我的应用程序崩溃而没有任何错误或警告。我该如何解决这个问题?
我的代码是
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
boolean facebookAppFound = false;
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase() .contains(nameApp)) {
share.putExtra(Intent.EXTRA_SUBJECT, "subject");
share.putExtra(Intent.EXTRA_TEXT, "My Info");
share.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(imagePath)));
share.setPackage(info.activityInfo.packageName);
facebookAppFound = true;
break;
}
}
if (!facebookAppFound) {
String sharerUrl = "https://www.facebook.com/mypage/mypage.php?u=" + Uri.fromFile(new File(imagePath));
share = new Intent(Intent.ACTION_VIEW,
Uri.parse(sharerUrl));
}
}
else {
if (!facebookAppFound) {
String sharerUrl = "https://www.facebook.com/shwetech/shwetech.php?u=" + Uri.fromFile(new File(imagePath));
share = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
}
}
startActivity(Intent.createChooser(share, "Select"));
.....
完成此代码startActivity(Intent.createChooser(share, "Select"));
后,我的申请已结束。