Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Add your Application on Gallery Sharing option

    • 0
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 383
    Comment on it

    Add your App on Gallery Sharing option.

    If you want to add image sharing from gallery option to your application, there is a perfect code for this requirement..

    You just need to add these lines to your manifest file on that activity which you want to open when you share image/images from gallery to your application.

    <action android:name="android.intent.action.SEND" /> This is for single image

    <action android:name="android.intent.action.SEND_MULTIPLE" /> This is for multiple image.

     <activity
                <android:name="PhotoSharingActivity"
                <android:label="@string/title_activity_images_showing"
               <android:screenOrientation="portrait" >
              <intent-filter>
                    <action android:name="android.intent.action.SEND" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <data android:mimeType="image/*" />
                </intent-filter>
                <intent-filter>
                    <action android:name="android.intent.action.SEND_MULTIPLE" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <data android:mimeType="image/*" />
                </intent-filter>
            </activity>
    

    And in your Activity's onCreate() add receive the images like this.

    Intent receivedIntent = getIntent();
            String receivedAction = receivedIntent.getAction();
            String receivedType = receivedIntent.getType();
            //make sure it's an action and type we can handle
            if(receivedAction.equals(Intent.ACTION_SEND)){
                //content is being shared   
                //sharedImage.setVisibility(View.VISIBLE);
                if(receivedType.startsWith("image/")){
                    //handle sent image
                    Uri receivedUri = (Uri)receivedIntent.getParcelableExtra(Intent.EXTRA_STREAM);
                    if (receivedUri != null) {
                        uriArrayList.add(receivedUri);
                        mAdapter = new MyAdapter(getSupportFragmentManager());
                        viewPager.setAdapter(mAdapter);
                        sharedImage.setImageURI(receivedUri);//just for demonstration
                    }
                }
            }
    //For multiple images
            if (Intent.ACTION_SEND_MULTIPLE.equals(getIntent().getAction()) && getIntent().hasExtra(Intent.EXTRA_STREAM)) {
                ArrayList list = getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
                sharedImage.setVisibility(View.GONE);
                for (Parcelable parcel : list) {
                    Uri uri = (Uri) parcel;
                    Uri[] ur;
                    uriArrayList.add(uri);
                    String sourcepath=getPath(uri);
                    imagePathArrayList.add(sourcepath);
                }
                mAdapter = new MyAdapter(getSupportFragmentManager());
                viewPager.setAdapter(mAdapter);
            }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: