Important! A new Community experience launched on September 26, 2017. Read more about it here or continue to Base Camp.
Voting: 
Vote up!
0 Votes
2 Replies
Unanswered

Share Functionality using Kony Native function API

Question asked by Lakshmi Vennamaneni on Jul 13, 2017 07:10 EDT

Hi, I would like to implement the Sharing functionality(through medium Facebook,Twitter,Gamil etc etc) using Kony Native function API but I am not finding any API related to this. I know we can implement using FFI but currently I am looking if I can implement using Kony Native function API. Is this possible? if yes, can you please share the API details. Thanks

Vote up!
0 votes
Vote down!

Attached sample application which contains share functionality for iphone and android.It can be imported in Viz 7.2 or above.

Below is the code snippet thats available in the shared application

/**
  * @function shareAboutAppInAndroid
  * this function is for share or recommend this application to other users
  * this function will be called onClick of the share button
  * end
  */
function shareAboutAppInAndroid(){
  
  var KonyMain = java.import("com.konylabs.android.KonyMain");
  var Intent = java.import("android.content.Intent");
  var String=java.import("java.lang.String");
  var intentObject=new Intent(Intent.ACTION_SEND);  
  intentObject.setType("text/plain");
  intentObject.putExtra(Intent.EXTRA_SUBJECT, "Kony Edification");
  //var str = new String("");
  var str =  "Look at this awesome Kony Edification application for aspiring Kony Developers -> http://www.konyhackathon.com/KonyEdification";
  intentObject.putExtra(Intent.EXTRA_TEXT, str);  
  var contextObject = KonyMain.getActContext();
  contextObject.startActivity(Intent.createChooser(intentObject, "choose one"));
}

function shareAboutAppIniPhone(){ 
 
  var textToShare = "Look at this awesome Kony Edification application for aspiring Kony Developers -> http://www.konyhackathon.com/KonyEdification";
  var NSURL = objc.import("NSURL");
  var NSURLObjectLink=NSURL.URLWithString("http://www.konyhackathon.com/KonyEdification");
  var shareItems = [textToShare, NSURLObjectLink];
 var UIActivityViewController = objc.import("UIActivityViewController");
  var avcObject=UIActivityViewController.alloc().initWithActivityItemsApplicationActivities(shareItems, undefined);
  //var avcObject=UIActivityViewController.alloc().jsinit();
  //avcObject.initWithActivityItemsApplicationActivities(shareItems,null);
 //  UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
 //self.presentViewControllerAnimatedCompletion(avcObject,true,undefined);
  var UIApplication = objc.import("UIApplication");
  UIApplication.sharedApplication().keyWindow.rootViewController.presentViewControllerAnimatedCompletion(avcObject, true, undefined);
    //self presentViewController:avc animated:YES completion:nil];
  
  
  //NSString *textToShare = @"Look at this awesome website for aspiring iOS Developers!";
  //  NSURL *myWebsite = [NSURL URLWithString:@"http://www.codingexplorer.com/"];
 
  //  NSArray *objectsToShare = @[textToShare, myWebsite];
 
  //  UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];

  
  
   
}


function getDeviceInfoAndShare(){
  //#ifdef android
  shareAboutAppInAndroid()
  //#else
  shareAboutAppIniPhone();
  //#endif
}

 

 

Replied by: Jul 13, 2017 07:38 EDT
Vote up!
0 votes
Vote down!

Thanks Pavan for your reply.

For iOS, can you please suggest how do I set the subject?  textToShare  is coming in body of the email while sharing..Thanks

Replied by: Sep 12, 2017 00:23 EDT