无法通过蓝牙共享....文件未发送错误

时间:2015-09-04 07:14:53

标签: java android android-intent bluetooth share

这是我的代码:

List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent sharingIntent = new  Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
PackageManager pm =getApplicationContext().getPackageManager();
List<ResolveInfo> activityList =   pm.queryIntentActivities(sharingIntent, 0);

for(final ResolveInfo app : activityList) {
    String packageName = app.activityInfo.packageName;
    Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
    targetedShareIntent.setType("text/plain");
    targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "share");

    if(TextUtils.equals(packageName, "com.facebook.katana")){
        targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http:your link");
    } else {
        targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT,  Fragmentactivity.songpaths.get(indexfordelete));
        targetedShareIntent.putExtra(Intent.EXTRA_SUBJECT, " Thirukural Version 1.7.2 !");
    }
    targetedShareIntent.setPackage(packageName);
    targetedShareIntents.add(targetedShareIntent);
}

Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Share Application  your app name ");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);

我试图首先通过蓝牙分享它,但它无法正常工作。我收到了错误〜File not sentFragmentactivity.songpaths.get(indexfordelete)是我想要分享的文件的路径。

1 个答案:

答案 0 :(得分:2)

在这里尝试此代码我共享文本,你可以分享你想要的东西:

List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent sharingIntent = new      Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
PackageManager pm =v.getContext().getPackageManager();
List<ResolveInfo> activityList =   pm.queryIntentActivities(sharingIntent, 0);

for(final ResolveInfo app : activityList) {
    String packageName = app.activityInfo.packageName;
    Intent targetedShareIntent = new Intent(android.content.Intent.ACTION_SEND);
    targetedShareIntent.setType("text/plain");
    targetedShareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "share");

    if(TextUtils.equals(packageName, "com.facebook.katana")){
        targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http:your link");
    } else {
        targetedShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, strLink);
        targetedShareIntent.putExtra(Intent.EXTRA_SUBJECT, " app version");
    }
    targetedShareIntent.setPackage(packageName);
    targetedShareIntents.add(targetedShareIntent);
}

Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Share Application  your app name ");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);