Skip to content

Commit

Permalink
fix: excludeActivityTypes in android (#750)
Browse files Browse the repository at this point in the history
Co-authored-by: Rupam Ghosh <rupam.ghosh@thoughtspot.com>
Co-authored-by: Mateus Andrade <mateus.andrade47@outlook.com>
  • Loading branch information
3 people committed Jun 9, 2020
1 parent 10c72e4 commit 4e655e1
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion android/src/main/java/cl/json/social/ShareIntent.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.facebook.react.bridge.ReadableMap;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -249,7 +250,7 @@ protected void openIntentChooser() throws ActivityNotFoundException {

if (ShareIntent.hasValidKey("excludedActivityTypes", options)) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
chooser.putExtra(Intent.EXTRA_EXCLUDE_COMPONENTS, options.getArray("excludedActivityTypes").toString());
chooser.putExtra(Intent.EXTRA_EXCLUDE_COMPONENTS, getExcludedComponentArray(options.getArray("excludedActivityTypes")));
activity.startActivityForResult(chooser, RNShareModule.SHARE_REQUEST_CODE);
}else {
activity.startActivityForResult(excludeChooserIntent(this.getIntent(),options), RNShareModule.SHARE_REQUEST_CODE);
Expand Down Expand Up @@ -294,4 +295,23 @@ protected String getComponentClass() {
protected abstract String getDefaultWebLink();

protected abstract String getPlayStoreLink();

private ComponentName[] getExcludedComponentArray(ReadableArray excludeActivityTypes){
if (excludeActivityTypes == null){
return null;
}
Intent dummy = new Intent(getIntent().getAction());
dummy.setType(getIntent().getType());
List<ComponentName> componentNameList = new ArrayList<>();
List<ResolveInfo> resInfoList = this.reactContext.getPackageManager().queryIntentActivities(dummy, 0);
for (int index = 0; index < excludeActivityTypes.size(); index++) {
String packageName = excludeActivityTypes.getString(index);
for(ResolveInfo resInfo : resInfoList) {
if(resInfo.activityInfo.packageName.equals(packageName)) {
componentNameList.add(new ComponentName(resInfo.activityInfo.packageName, resInfo.activityInfo.name));
}
}
}
return componentNameList.toArray(new ComponentName[]{});
}
}

0 comments on commit 4e655e1

Please sign in to comment.