Skip to content

Commit

Permalink
Merge pull request #96 from hansemannn/fix-android-sharing
Browse files Browse the repository at this point in the history
Fix Android "presentPhotoShareDialog" API
  • Loading branch information
hansemannn authored Aug 9, 2018
2 parents 5ac8113 + 8272240 commit d44f4c5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ The app id goes into the the file `/platform/android/res/values/strings.xml` (cl
```
where the number is of course the app ID. The app ID is not set programmatically.

Finally, if using sharing capabilities, you should add the content provider settings as well:
```xml
<provider android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider<YOUR_APP_ID>"
android:exported="true" />
```

Android Key Hash for Facebook Developer Profile
---

Expand Down
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 7.3.0
version: 7.3.1
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86
description: facebook
Expand Down
34 changes: 28 additions & 6 deletions android/src/facebook/TiFacebookModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.TiFileProxy;
import org.appcelerator.titanium.TiLifecycle.OnActivityResultEvent;
import org.appcelerator.titanium.util.TiConvert;
import org.json.JSONArray;
Expand Down Expand Up @@ -626,10 +627,26 @@ public void onSuccess(Sharer.Result results)

Mode mode = Mode.AUTOMATIC;
Object[] proxyPhotos = (Object[]) args.get("photos");

KrollDict[] photos = Arrays.copyOf(proxyPhotos, proxyPhotos.length, KrollDict[].class);
KrollDict[] photos = new KrollDict[proxyPhotos.length];
SharePhotoContent shareContent = null;

for (int i = 0; i < proxyPhotos.length; i++) {
HashMap obj = (HashMap) proxyPhotos[i];
KrollDict dict = new KrollDict();

dict.put("photo", obj.get("photo"));

if (obj.containsKey("caption")) {
dict.put("caption", (String) obj.get("caption"));
}

if (obj.containsKey("userGenerated")) {
dict.put("userGenerated", (boolean) obj.get("userGenerated"));
}

photos[i] = dict;
}

switch (TiConvert.toInt(args.get("mode"), TiFacebookModule.SHARE_DIALOG_MODE_AUTOMATIC)) {
case TiFacebookModule.SHARE_DIALOG_MODE_NATIVE:
mode = Mode.NATIVE;
Expand All @@ -656,12 +673,15 @@ public void onSuccess(Sharer.Result results)
boolean userGenerated = proxyPhoto.optBoolean("userGenerated", false);

// A photo can either be a Blob or String
if (photo instanceof TiBlob) {
if ((photo instanceof TiBlob) || (photo instanceof TiFileProxy)) {
if (photo instanceof TiFileProxy) {
photo = TiBlob.blobFromFile(((TiFileProxy) photo).getBaseFile());
}
photoBuilder = photoBuilder.setBitmap(((TiBlob) photo).getImage());
} else if (photo instanceof String) {
photoBuilder = photoBuilder.setImageUrl(Uri.parse((String) photo));
} else {
Log.e(TAG, "Required \"photo\" not found or of unknown type: " + photo.getClass().getSimpleName());
Log.e(TAG, "Required \"photo\" not found or of unknown type: " + photo.getClass().getName());
}

// An optional caption
Expand All @@ -681,8 +701,10 @@ public void onSuccess(Sharer.Result results)
Log.e(TAG, "The \"photos\" property is required when showing a photo share dialog.");
}

if (shareDialog != null && shareDialog.canShow(shareContent, mode)) {
shareDialog.show(shareContent, mode);
if (shareDialog != null && shareDialog.canShow(SharePhotoContent.class)) {
shareDialog.show(shareContent);
} else {
Log.e(TAG, "Cannot show image share dialog due to unsupported device or configuration!");
}
}

Expand Down
11 changes: 11 additions & 0 deletions apidoc/Facebook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ description: |
android:label="YourAppName"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<provider android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider<YOUR_APP_ID>"
android:exported="true" />
</application>
</manifest>
</android>
Expand Down Expand Up @@ -593,6 +597,13 @@ methods:
Note: The `images` parameter is **required** by the Facebook SDK.
Android Note: In order to share images on Android, the Facebook app needs to be installed and the
"content provider" settings in your Android manifest needs to be configured:
<provider android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider<YOUR_APP_ID>"
android:exported="true" />
Listen for the <Modules.Facebook.shareCompleted> to be notified if the attempt was
successful or not.
parameters:
Expand Down

0 comments on commit d44f4c5

Please sign in to comment.