3

I have used this code to share image from drawable folder and its opening "Share intent" with list of available sharing possibilities i.e Bluetooth , Gmail ,FB etc.But on Sending file using Bluetooth gives me error "Unable to Open file for Sharing" when trying to share image from Assets folder while getting error "File not sent" when trying to share file from "drawable folder".Can someone please hele me how to share image file using Android.........here is the 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"));
        }
    }
user3233280
  • 279
  • 2
  • 7
  • 21

1 Answers1

0

Use this

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"));
Govind Narayan
  • 91
  • 1
  • 12
  • have applied your changes but getting alert of bluetooth on other device after accepting request its showing me error "File not sent" on sending device – user3233280 Jan 27 '14 at 05:51
  • when i send email via gmail it successfully send but when i download image from email its showing invalid image which indicates there is smoe small problem – user3233280 Jan 27 '14 at 05:57