Hello every one! Today I posting to Skype calls and message from our application. Just we need to open explicit default installed Skype application through Intent.
1. Focus Skype (Open Skype Application)
Uri skypeUri = Uri.parse("skype:");
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
2. Skype Chat
Uri skypeUri = Uri.parse("skype:username?chat");
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
3. Skype Conference Chat with Topic
Uri skypeUri = Uri.parse("skype:username1;username2?chat&topic=Android%20Chat");
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
4. Make a Skype call
Uri skypeUri = Uri.parse("skype:username?call");
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
5. Make a Skype Video call
Uri skypeUri = Uri.parse("skype:username?call&video=true");
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myIntent);
Example code here.
MainActivity.java Class file
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity
{
// Make sure you are sign in skype application if you not then you need to sign in
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Open skype button click event code here
((Button) findViewById(R.id.openskype)).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String mySkypeUri = "skype:";
SkypeUri(MainActivity.this, mySkypeUri);
}
});
// skype message button click event code here
((Button) findViewById(R.id.skypemsg)).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String skypeName = ((EditText) findViewById(R.id.edt_skypeusername)).getText().toString().trim();
if(skypeName.length()<=0)
{
Toast.makeText(getApplicationContext(), "Please enter skype username to message", Toast.LENGTH_SHORT).show();
}
else
{
String mySkypeUri = "skype:"+skypeName+"?chat";
SkypeUri(MainActivity.this, mySkypeUri);
}
}
});
// Skype Audio call button click event code here
((Button) findViewById(R.id.skypecall)).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String skypeName = ((EditText) findViewById(R.id.edt_skypeusername)).getText().toString().trim();
if(skypeName.length()<=0)
{
Toast.makeText(getApplicationContext(), "Please enter skype username to call", Toast.LENGTH_SHORT).show();
}
else {
String mySkypeUri = "skype:"+skypeName+"?call";
SkypeUri(MainActivity.this, mySkypeUri);
}
}
});
// Skype Video call button click event code here
((Button) findViewById(R.id.skypevideocall)).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
String skypeName = ((EditText) findViewById(R.id.edt_skypeusername)).getText().toString().trim();
if(skypeName.length()<=0)
{
Toast.makeText(getApplicationContext(), "Please enter skype username to video call", Toast.LENGTH_SHORT).show();
}
else
{
String mySkypeUri = "skype:"+skypeName+"?call&video=true";
SkypeUri(MainActivity.this, mySkypeUri);
}
}
});
}
public void SkypeUri(Context myContext, String mySkypeUri) {
// Make sure the Skype for Android client is installed.
if (!isSkypeClientInstalled(myContext)) {
goToMarket(myContext);
return;
}
Uri skypeUri = Uri.parse(mySkypeUri);
Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myContext.startActivity(myIntent);
return;
}
/**
* Determine whether the Skype for Android client is installed on this device.
*/
public boolean isSkypeClientInstalled(Context myContext) {
PackageManager myPackageMgr = myContext.getPackageManager();
try {
myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES);
}
catch (PackageManager.NameNotFoundException e) {
return (false);
}
return (true);
}
/**
* Install the Skype client through the market: URI scheme.
*/
public void goToMarket(Context myContext) {
Uri marketUri = Uri.parse("market://details?id=com.skype.raider");
Intent myIntent = new Intent(Intent.ACTION_VIEW, marketUri);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myContext.startActivity(myIntent);
return;
}
}
activity_main.xml XML layout file Here
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp"
tools:context=".MainActivity" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/skype_intent_handler"
android:textSize="18sp"
android:textStyle="bold" />
<EditText
android:id="@+id/edt_skypeusername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:ems="10"
android:hint="Echo Testing skypeID - echo123" >
</EditText>
<Button
android:id="@+id/openskype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Open Skype" />
<Button
android:id="@+id/skypemsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Skype Message" />
<Button
android:id="@+id/skypecall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Skype Audio Call" />
<Button
android:id="@+id/skypevideocall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Skype Video Call" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.limbani.skypeintenthandler"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.limbani.skypeintenthandler.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Note: Make sure you sign in Skype application. If not then open Skype application and sign in.
More information about Skype URIs are documented at: developer.skype.com/skype-uris-program/skype-uri-ref
Download Tutorial APK file ClickHere
Enjoy :)