IntentShare


Source link: https://github.com/tvbarthel/IntentShare

IntentShare

This project is a light open-source library that improves the sharing experience on Android.

Motivations

Nowadays, sharing content is part of our daily life. Unfortunately, the Android framework tools do not provide a sharing experience which reaches all of our expectations. We decided to implement our own tool, IntentShare, that might improve the user experience of a sharing action by :

  • providing different extras according to the chosen target activity in order to take advantages of each target's specificities.
  • providing an easy way to track the selected target activities in order to improve/adapt the extras for a specific target.
  • providing a sorted target activity list based on the context of your app in order to take advantages of how people use it.

Find more about our motivations here.

Sample app

Sample app available on the PlayStore

Gradle dependency

available on jcenter.

compile 'fr.tvbarthel.intentshare:library:0.0.4'

dependencies

compile 'com.android.support:appcompat-v7:25.0.0' compile 'com.android.support:recyclerview-v7:25.0.0'

Usage

Simple usage

IntentShare.with(context)
  .text("Default text you would like to share.")
  .deliver();

Dialog label

IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .deliver();

Image

IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .image(Uri.parse("content://com.example.test.fileprovider/data/img.png"))
  .deliver();

Extra Provider

An extra provider can specify shared content for a given target activity.

Build-in extra provider

Facebook

IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .image(Uri.parse("content://com.example.test.fileprovider/data/img.png"))
  .facebookBody(Uri.parse("http://tvbarthel.fr"))
  .deliver();

Twitter

IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .image(Uri.parse("content://com.example.test.fileprovider/data/img.png"))
  .twitterBody("Tweet can only have 140 char!")
  .deliver();

Mail clients

IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .image(Uri.parse("content://com.example.test.fileprovider/data/img.png"))
  .mailSubject("Mail subject.")
  .mailBody("Extended text you would like to share in mail body.")
  .deliver();

Custom extra provider

IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .image(Uri.parse("content://com.example.test.fileprovider/data/img.png"))
  .addExtraProvider(

new IntentShare.ExtraProvider("com.google.android.gm")

 .disableText()

 .overrideSubject("Gmail subject, no mail body.")

 .disableImage()
  )
  .deliver();

By default, an ExtraProvider will copy the default shared content. Replace default shared content :

/**  * Provide a specific text for the linked package name.  *  * @param text text which will be used as {
@link android.content.Intent#EXTRA_TEXT
}
  * @return {
@link ExtraProvider
}
 for chaining.  */ public ExtraProvider overrideText(String text);
  /**  * Provide a specific subject for the linked package name.  *  * @param subject subject which will be used as {
@link android.content.Intent#EXTRA_SUBJECT
}
  * @return {
@link ExtraProvider
}
 for chaining.  */ public ExtraProvider overrideSubject(String subject);
  /**  * Provide a specific image for the linked package name.  *  * @param image image which will be used as {
@link android.content.Intent#EXTRA_STREAM
}
  * @return {
@link ExtraProvider
}
 for chaining.  */ public ExtraProvider overrideImage(Uri image);

Avoid copying default shared content without overriding:

/**  * Disable the extra {
@link android.content.Intent#EXTRA_TEXT
}
 for the linked package  * to avoid a copy from the default {
@link IntentShare
}
 text.  *  * @return {
@link ExtraProvider
}
 for chaining.  */ public ExtraProvider disableText();
  /**  * Disable the extra {
@link android.content.Intent#EXTRA_SUBJECT
}
 for the linked package  * to avoid a copy from the default {
@link IntentShare
}
 subject.  *  * @return {
@link ExtraProvider
}
 for chaining.  */ public ExtraProvider disableSubject();
  /**  * Disable the extra {
@link android.content.Intent#EXTRA_STREAM
}
 for the linked package  * to avoid a copy from the default {
@link IntentShare
}
 image.  *  * @return {
@link ExtraProvider
}
 for chaining.  */ public ExtraProvider disableImage();

Listener

intentShareListener = new IntentShareListener() {

  @Override
  public void onCompleted(String packageName) {

Log.d(TAG, "onCompleted : " + packageName);

  
}

@Override
  public void onCanceled() {

Log.d(TAG, "onCanceled");

  
}
 
}
;  IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .listener(intentShareListener)
  .deliver();

Icon loader

Default icon loader used to load target activities icons is based on AsyncTask.

Picasso

If your are already using Picasso, you may want to consider using PicassoIconLoader:

compile 'fr.tvbarthel.intentshare:picasso-loader:0.0.4'
IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .iconLoader(new PicassoIconLoader())
  .deliver();

Glide

If your are already using Glide, you may want to consider using GlideIconLoader:

compile 'fr.tvbarthel.intentshare:glide-loader:0.0.4'
IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .iconLoader(new GlideIconLoader())
  .deliver();

Custom icon loader

Implement your own IconLoader:

IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .iconLoader(new IconLoader() {

@Override

public void load(Uri iconUri, ImageView imageView) {

 
}

 @Override

public void cancel(ImageView imageView) {

 
}

  
}
)
  .deliver();

Comparator provider

By default, target activities are sorted based on the recency of their selection from your app.


  /** 

* Comparator used to sort {
@link TargetActivity
}
 based on the recency of their previous 

* selection and their default order as fallback when they have never been selected. 

* <p/> 

* The ordering imposed by this comparator on a set of {
@link TargetActivity
}
 

* is not consistent with equals since c.compare(e1, e2)==0 has not the same boolean 

* value as e1.equals(e2). 

*/

public RecencyComparatorProvider() {

 
}

Instead of using the default comparator, you can implement your own comparator provider in order to customize the target activities order display to the user:

/**  * ?Interface which allow to define which comparator will be provided for sorting the  * target activity inside the {
@link TargetChooserActivity
}
.  */ public interface TargetActivityComparatorProvider extends Parcelable {

/** 
  * Provide the comparator used to sort {
@link TargetActivity
}
 displayed to the user. 
  * 
  * @return comparator used to sort {
@link TargetActivity
}
 displayed to the user. 
  */
  Comparator<TargetActivity> provideComparator();
 
}
IntentShare.with(context)
  .chooserTitle("Select a sharing target : ")
  .text("Default text you would like to share.")
  .comparatorProvider(customComparatorProvider)
  .deliver();

An example from the sample can be found here : SocialTargetActivityComparatorProvider.java

Release Note

  • 0.0.4: min sdk set to 14.
  • 0.0.3: Tweet length check no longer performed (see #39). allowbackup disable by default.

What's next

  • Providing easier way to share images.
  • Removing dependencies on support libraries.
  • Sample : implementing image selection for extra provider.

Contributing

Contributions are very welcome (: You can contribute through GitHub by forking the repository and sending a pull request.

When submitting code, please make sure ./gradlew check succeed.

License

Copyright (C) 2016 tvbarthel  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Special Thanks to ...

Vincent Brison https://github.com/vincentbrison , for his precious advice. Stéphane Guérin https://github.com/guerwan , for his helpful feedback. Romain Zanon https://github.com/romainz , for his early day support.

Resources

With SaveInsta download all Instagram photos and videos that you love.

AndroidTampering is a library that provides an extra layer of security to your Android application. This library protects your application against simple tampering attacks. Please note that this protection methods can also be hacked. So, besides the tampering protection, don't forget to add all the other security recommendations.

App to update to the latest version of WhatsApp for Android. Beta Updater for WhatsApp checks the latest beta version available on whatsapp.com and allows to install it automatically.

A simple extension to the standard Android EditText which shows an icon on the right side of the field and lets the user toggle the visibility of the password he puts in.

Material Design Stepper Library for Android.

A library which provides an RxJava wrapper for google maps.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes