|
|
|
|
|
import android.content.Context |
|
import android.content.Intent |
|
import android.content.pm.PackageManager |
|
import android.net.Uri |
|
|
|
|
|
object SocialLinkHelper { |
|
|
|
/** |
|
* Handle Facebook social link click |
|
*/ |
|
fun facebook(context: Context, username: String) { |
|
try { |
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=https://www.facebook.com/$username")) |
|
context.startActivity(intent) |
|
} catch (e: Exception) { |
|
val intent = Intent( |
|
Intent.ACTION_VIEW, |
|
Uri.parse("https://www.facebook.com/$username") |
|
) |
|
context.startActivity(intent) |
|
} |
|
} |
|
|
|
/** |
|
* Handle LinkedIn social link click |
|
*/ |
|
fun linkedIn(context: Context, username: String) { |
|
var intent = Intent(Intent.ACTION_VIEW, Uri.parse("linkedin://add/%@$username")) |
|
val packageManager: PackageManager = context.packageManager |
|
val list = packageManager.queryIntentActivities(intent!!, PackageManager.MATCH_DEFAULT_ONLY) |
|
if (list.isEmpty()) { |
|
intent = Intent( |
|
Intent.ACTION_VIEW, |
|
Uri.parse("http://www.linkedin.com/profile/view?id=$username") |
|
) |
|
} |
|
context.startActivity(intent) |
|
} |
|
|
|
/** |
|
* Handle Whatsapp social link click |
|
*/ |
|
fun whatsapp(context: Context, phoneNumber: String) { |
|
val url = "https://api.whatsapp.com/send?phone=$phoneNumber" |
|
try { |
|
val pm = context.packageManager |
|
pm.getPackageInfo("com.whatsapp", PackageManager.GET_ACTIVITIES) |
|
val intent = Intent(Intent.ACTION_VIEW) |
|
intent.data = Uri.parse(url) |
|
context.startActivity(intent) |
|
} catch (e: PackageManager.NameNotFoundException) { |
|
val intent = Intent( |
|
Intent.ACTION_VIEW, |
|
Uri.parse(url) |
|
) |
|
context.startActivity(intent) |
|
} |
|
} |
|
} |