【问题标题】:Unable to open File For sharing while sharing image file using intent in Android?在Android中使用意图共享图像文件时无法打开文件进行共享?
【发布时间】:2014-01-27 05:33:51
【问题描述】:

我已使用此代码共享可绘制文件夹中的图像及其打开的“共享意图”以及可用共享可能性列表,即蓝牙、Gmail、FB 等。但是在使用蓝牙发送文件时出现错误“无法尝试从 Assets 文件夹共享图像时打开文件以共享”,而在尝试从“drawable 文件夹”共享文件时出现错误“文件未发送”。有人可以帮我如何使用 Android 共享图像文件............这是 Manifest File

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.shareima"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
 <uses-permission android:name="android.permission.BLUETOOTH"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.shareima.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



    </application>

</manifest>

MainActivity.java

 public class MainActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/png");
           Uri imageUri = Uri.parse("android.resource://com.example.shareima/drawable/ic_launcher");
            Log.i("imageUri",""+imageUri);
            share.putExtra(Intent.EXTRA_STREAM,imageUri);
            startActivity(Intent.createChooser(share,"Share Image"));
        }
    }

【问题讨论】:

标签: java android android-intent bluetooth


【解决方案1】:

使用这个

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/png");
Uri uri = Uri.parse("android.resource://your package name/"+R.drawable.ic_launcher);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello, This is test Sharing");
startActivity(Intent.createChooser(shareIntent, "Send your image"));

【讨论】:

  • 已应用您的更改,但在接受请求后收到其他设备上的蓝牙警报,在发送设备上显示错误“文件未发送”
  • 当我通过 gmail 发送电子邮件时,它成功发送,但是当我从电子邮件下载图像时,它显示的图像无效,这表明存在 smoe 小问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多