Skip to content

Instantly share code, notes, and snippets.

@MaTriXy
Created October 30, 2015 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaTriXy/adeacdf5496bcdae5f42 to your computer and use it in GitHub Desktop.
Save MaTriXy/adeacdf5496bcdae5f42 to your computer and use it in GitHub Desktop.
MyChooserTargetService extends ChooserTargetService as an Example
public class MyChooserTargetService extends ChooserTargetService {
private String mDirectShareTargetName;
private final int MAX_SHARE_TARGETS=5;
@Override
public void onCreate() {
super.onCreate();
mDirectShareTargetName=“Sharing Person demo #%d”;
}
@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName sendTarget, IntentFilter matchedFilter) {
ArrayList<ChooserTarget> result=new ArrayList<ChooserTarget>();
for (int i=1;i<=MAX_SHARE_TARGETS;i++) {
result.add(buildTarget(i));
}
return(result);
}
private ChooserTarget buildTarget(int targetId) {

String title=String.format(mDirectShareTargetName, targetId);


Icon icon=Icon.createWithResource(this, R.drawable.share_target_picture);

float target_value=((float)(25-targetId)/25);
ComponentName componentName=new ComponentName(MyChooserTargetService.this, TargetActivity.class);
Bundle bundle=new Bundle();
bundle.putInt(“simple_key”, targetId);
return(new ChooserTarget(title, icon, target_value, componentName, bundle));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment