Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement