Pages

Thursday, January 2, 2014

How to make a Skype Audio/Video call and Chat through intent in Android


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 :)

49 comments:

  1. Good work. Very useful u made it in simple way.Thats working very fine and while making it i feli enjoyed and interesting.U made an awesome post.
    Skype Technical Help

    ReplyDelete
    Replies
    1. hello .is this video call coding please tell me

      Delete
    2. hello .is this video call coding please tell me

      Delete
  2. can u post code for starting video call???

    ReplyDelete
    Replies
    1. Hello Nithya Mohan,
      I have update my post. i hope it is help you.

      Thanks

      Delete
  3. thank you soo much... :) :) cn u post the manifest and string xml files of above code.....????

    ReplyDelete
    Replies
    1. Hello Nithya Mohan,
      Just create new application on your eclipse and copy my code on your application. Add your create activity on manifest no need add more code. That's it.

      Delete
  4. thank you so much Durgesh Limbani... :) :) :) that was a great favor from your side......:):)

    ReplyDelete
  5. i had run skype in background...bt still its not working...we are suposed to move to next page right after clicking each button...bt its not working.... :( :( :(

    ReplyDelete
    Replies
    1. Hello Nithya,
      It's work for me,
      Can you tell me which error came?
      when you click button then open Skype application or not?
      Thanks

      Delete
    2. Hello Nathya,

      I have updated my code. Please check it, I hope it's working for you now.

      Thanks

      Delete
  6. hello Durgesh.....'
    can u pls tell me what happens when you click each of four option in the app....?????

    Thanks

    ReplyDelete
    Replies
    1. Hey Nithya,

      for me all above option working for me.
      when m click on button then it's perform define action.(open Skype app).
      Can you send me your code on mail - durgesh.android@gmail.com?
      So I can check your code if possible. I can fix your issues.

      Thanks

      Delete
  7. hello durgesh......

    i ws able to open skype with your code...bt calling and messaging dint work for me..........

    thanks....

    ReplyDelete
  8. Can you show me the Manifest, Thanks.

    ReplyDelete
    Replies
    1. Hello, I have add menifest code now please check.

      Thank you

      Delete
    2. Thank you so much, I have fix the Manifest file but I don't know why have this error

      android.content.ActivityNotFoundException: Unable to find explicit activity class {com.skype.raider/com.skype.raider.Main}; have you declared this activity in your AndroidManifest.xml?

      Delete
    3. Hello Duy,

      I have not declared this "com.skype.raider/com.skype.raider.Main" activity in AndroidMenifest.xml file.

      android.content.ActivityNotFoundException error came bucz Skype application not installed on your device. first install then try it.

      Thanks

      Thanks

      Delete
    4. Oh my fail, I test on emulator so have some error as that. Thank for the awesome post!

      Delete
    5. This comment has been removed by the author.

      Delete
  9. Ok, it work fine, but if i want have the function on skype is chat room,how to do it. Thank!

    ReplyDelete
    Replies
    1. I am very happy it's work for you. Thank you

      "but if i want have the function on skype is chat room" you mean you want conference chat?
      if yes then you use 3 point in post.


      Delete
    2. I follow conference chat but what wrong with my code
      String skypeName1=((EditText)findViewById(R.id.edt_skypeusername)).getText().toString().trim();
      String skypeName2=((EditText)findViewById(R.id.edt_skypeusername2)).getText().toString().trim();
      Uri skypeUri=Uri.parse("skype:"+skypeName1+", "+skypeName2+"?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);

      It don't understand skypeName1 and skypeName2 :(. Thank you!

      Delete
    3. Hello Duy,

      If you want create conference chat in Skype then you need to add two or more people right?

      so Skypename mean that's users skypeid. you need to add skypeid which user to need to add in conference. you must know user skypeID.
      I hope now it's clear.

      Thanks
      Durgesh



      Delete
  10. Yes, i know that, my mean is my code wrong in
    Uri skypeUri=Uri.parse("skype:"+skypeName1+", "+skypeName2+"?chat&topic=Android%20Chat");
    skypeName1 and skypeName2 are 2 skypeId have on my contact. Thank for replay, hope you can help me, Thank Durgesh Limbani :)

    ReplyDelete
    Replies
    1. Hello Duy,


      just replace "," to semicolon ";" here
      Uri skypeUri=Uri.parse("skype:"+skypeName1+";"+skypeName2+"?chat&topic=Android%20Chat");

      Thank you..

      Delete
    2. Ok, It work fine, it is what i need, you are very kind, thank you so much, good morning :)

      Delete
    3. can you please send the code i have tried it many times but still showing errors.. please send me i am waiting...i need it quick

      Delete
  11. Helloo Durgesh....

    Is there any way to convert the data received from a bluetooth modem to skype message....???

    ReplyDelete
  12. hello Durgesh
    i wanted to fetch the skype contact list in my application ?? Any suggestion plz

    ReplyDelete
  13. is there a way to return to the application at the end of the call?
    many thanks for your work!!
    /davide

    ReplyDelete
  14. please send me whole code in zip file

    ReplyDelete
  15. if i haven't skype on my mob phone it is not work. what can i do?

    ReplyDelete
    Replies
    1. Hello,
      I have update my post. Now first check Skype install or not in device, if not install then goto Market to install first Skype application.
      Thanks.

      Delete
  16. Hi durgesh.
    i want to send voice stream from one android device to multiple android device via server.Can u help me on that??

    ReplyDelete
  17. hi durgesh
    you have shown only audio call between two users.But i read the skype uri api and saw that android device can't host conversation.But i need it.Actually i need to send audio streaming from one android device to multiple devices.How can i do that??will u plz write a tutorial on that??

    ReplyDelete
  18. Hi, I am getting an error while running an App Android Library Projects Can't Launch.

    ReplyDelete
  19. hi, I am getting an error on logcat android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://details?id=com.skype.raider flg=0x10000000 }

    ReplyDelete
  20. i have error on
    SkypeUri(MainActivity.this, mySkypeUri);

    ReplyDelete
  21. i have error on
    SkypeUri(MainActivity.this, mySkypeUri);

    ReplyDelete
  22. Is it possible to send message to skype from a phone???

    ReplyDelete
  23. Plz attached all code like croping the image and clicking image with camera

    ReplyDelete
  24. Is it possible to go to the chat screen of someone, based on his contact-id or phone number? How do I get the skype-user-name from the API?

    ReplyDelete
  25. The quality of studying from a web based math lesson will reflect in your effectiveness in solving distinct problems related to math. It is possible to apply this learning to your classroom discussions at your college.https://800support.net/sign-in/gmail-sign-in-gmail-login/

    ReplyDelete
  26. can u please help me to make video call in android studio project?

    ReplyDelete
  27. Hello,
    i have problems with a new version of skype this code only opens skype . Can you please help me :)

    ReplyDelete