Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. import android.app.Activity;
  2. import android.content.ComponentName;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.content.pm.PackageManager;
  6. import android.net.Uri;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.Button;
  11. import android.widget.EditText;
  12. import android.widget.Toast;
  13.  
  14. public class MainActivity extends Activity
  15. {
  16.  // Make sure you are sign in skype application if you not then you need to sign in
  17.  @Override
  18.  protected void onCreate(Bundle savedInstanceState)
  19.  {
  20.   super.onCreate(savedInstanceState);
  21.   setContentView(R.layout.activity_main);
  22.  
  23.   // Open skype button click event code here
  24.   ((Button) findViewById(R.id.openskype)).setOnClickListener(new OnClickListener()
  25.   {
  26.    @Override
  27.    public void onClick(View v)
  28.    {
  29.     String mySkypeUri = "skype:";
  30.     SkypeUri(MainActivity.this, mySkypeUri);
  31.    }
  32.   });
  33.  
  34.   // skype message button click event code here
  35.   ((Button) findViewById(R.id.skypemsg)).setOnClickListener(new OnClickListener()
  36.   {
  37.    @Override
  38.    public void onClick(View v)
  39.    {
  40.     String skypeName = ((EditText) findViewById(R.id.edt_skypeusername)).getText().toString().trim();
  41.     if(skypeName.length()<=0)
  42.     {
  43.      Toast.makeText(getApplicationContext(), "Please enter skype username to message", Toast.LENGTH_SHORT).show();
  44.     }
  45.     else
  46.     {
  47.      String mySkypeUri = "skype:"+skypeName+"?chat";
  48.      SkypeUri(MainActivity.this, mySkypeUri);
  49.     }
  50.    }
  51.   });
  52.  
  53.   // Skype Audio call button click event code here
  54.   ((Button) findViewById(R.id.skypecall)).setOnClickListener(new OnClickListener()
  55.   {
  56.    @Override
  57.    public void onClick(View v)
  58.    {
  59.     String skypeName = ((EditText) findViewById(R.id.edt_skypeusername)).getText().toString().trim();
  60.     if(skypeName.length()<=0)
  61.     {
  62.      Toast.makeText(getApplicationContext(), "Please enter skype username to call", Toast.LENGTH_SHORT).show();
  63.     }
  64.     else {
  65.      String mySkypeUri = "skype:"+skypeName+"?call";
  66.      SkypeUri(MainActivity.this, mySkypeUri);
  67.     }   
  68.    }
  69.   });
  70.  
  71.   // Skype Video call button click event code here
  72.   ((Button) findViewById(R.id.skypevideocall)).setOnClickListener(new OnClickListener()
  73.   {
  74.    @Override
  75.    public void onClick(View v)
  76.    {
  77.     String skypeName = ((EditText) findViewById(R.id.edt_skypeusername)).getText().toString().trim();
  78.     if(skypeName.length()<=0)
  79.     {
  80.      Toast.makeText(getApplicationContext(), "Please enter skype username to video call", Toast.LENGTH_SHORT).show();
  81.     }
  82.     else
  83.     {
  84.      String mySkypeUri = "skype:"+skypeName+"?call&video=true";
  85.      SkypeUri(MainActivity.this, mySkypeUri);
  86.     }   
  87.    }
  88.   });
  89.  }
  90.  
  91.  public void SkypeUri(Context myContext, String mySkypeUri) {
  92.    
  93.   // Make sure the Skype for Android client is installed.
  94.   if (!isSkypeClientInstalled(myContext)) {
  95.    goToMarket(myContext);
  96.    return;
  97.   }
  98.   Uri skypeUri = Uri.parse(mySkypeUri);
  99.   Intent myIntent = new Intent(Intent.ACTION_VIEW, skypeUri);
  100.   myIntent.setComponent(new ComponentName("com.skype.raider", "com.skype.raider.Main"));
  101.   myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  102.   myContext.startActivity(myIntent);
  103.  
  104.   return;
  105.  }
  106.   
  107.  /**
  108.   * Determine whether the Skype for Android client is installed on this device.
  109.   */
  110.  public boolean isSkypeClientInstalled(Context myContext) {
  111.   PackageManager myPackageMgr = myContext.getPackageManager();
  112.   try {
  113.    myPackageMgr.getPackageInfo("com.skype.raider", PackageManager.GET_ACTIVITIES);
  114.   }
  115.   catch (PackageManager.NameNotFoundException e) {
  116.    return (false);
  117.   }
  118.   return (true);
  119.  }
  120.  
  121.  /**
  122.   * Install the Skype client through the market: URI scheme.
  123.   */
  124.   
  125.  public void goToMarket(Context myContext) {
  126.   Uri marketUri = Uri.parse("market://details?id=com.skype.raider");
  127.   Intent myIntent = new Intent(Intent.ACTION_VIEW, marketUri);
  128.   myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  129.   myContext.startActivity(myIntent);
  130.   return;
  131.  }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement