我试图像调用意图
那样做一个意图 Intent skype = new Intent("android.intent.action.VIEW");
skype.setData(Uri.parse("skype:" + "user_name" + "?message=ddd"));
startActivity(skype);
它不起作用。
答案 0 :(得分:1)
官方Android SDK以及Skype URI的问题在于它们不允许共享预定义的消息。您只需打开与用户列表聊天(或清空以创建新用户)。如果您想明确与Skype分享一些文本,您可以尝试使用具有Skype软件包名称的系统Intents(请记住检查是否已安装此软件包名称,否则startActivity调用将使您的应用程序崩溃):
val SKYPE_PACKAGE_NAME = "com.skype.raider"
fun shareSkype(context: Context, message: String) {
if (!isAppInstalled(context, SKYPE_PACKAGE_NAME)) {
openAppInGooglePlay(context, SKYPE_PACKAGE_NAME)
return
}
val intent = context.packageManager.getLaunchIntentForPackage(SKYPE_PACKAGE_NAME)
intent.action = Intent.ACTION_SEND
intent.putExtra(Intent.EXTRA_TEXT, message)
intent.type = "text/plain"
context.startActivity(intent)
}
fun isAppInstalled(context: Context, packageName: String): Boolean {
val packageManager = context.packageManager
try {
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
} catch (e: PackageManager.NameNotFoundException) {
return false
}
return true
}
答案 1 :(得分:0)
如果Skype或其他Android消息传递应用程序没有公开可用的Intent,则在它们可用之前不可能这样做。
然而,您可以尝试找到Skype用于在您的应用程序中调用的代理服务,作为发送消息的方式。
http://developer.skype.com/skype-uris/reference#uriChats
注意:
<强>注意事项:强>
可选主题参数仅适用于多聊天。
必须转义主题参数值特定空格中的特殊字符。
Mac OS X:忽略任何主题参数。
iOS:不支持。
Android:仅识别初始参与者;不支持多聊天。
Android文档 - http://developer.skype.com/skype-uris/skype-uri-tutorial-android
/**
* Initiate the actions encoded in the specified URI.
*/
public void initiateSkypeUri(Context myContext, String mySkypeUri) {
// Make sure the Skype for Android client is installed
if (!isSkypeClientInstalled(myContext)) {
goToMarket(myContext);
return;
}
// Create the Intent from our Skype URI
Uri skypeUri = Uri.parse(mySkypeUri);
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
// Restrict the Intent to being handled by the Skype for Android client only
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Initiate the Intent. It should never fail since we've already established the
// presence of its handler (although there is an extremely minute window where that
// handler can go away...)
myContext.startActivity(myIntent);
return;
}