-
-
Save MaTriXy/adeacdf5496bcdae5f42 to your computer and use it in GitHub Desktop.
MyChooserTargetService extends ChooserTargetService as an Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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