android - 如果设备是平板电脑,如何打开 Skype,否则进行通话操作

标签 android skype phone-call

1)当我的应用程序启动时,它会显示带有调用按钮的警报对话框。如果是手机,我必须允许用户调用。如果是平板电脑,则单击按钮 Skype 应该打开,如果未安装 Skype,则打开游戏商店。

public class MainActivity extends Activity {
private Button call_btn, cancle_btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    call_btn = (Button) findViewById(R.id.call_button);
    cancle_btn = (Button) findViewById(R.id.cancel_button);
    call_btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:123456789"));
            startActivity(callIntent);

        }
    });

}

}

最佳答案

使用此方法,您实际上可以确定它是平板电脑还是手机:

public static boolean isTablet(Context context) {
        return (context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

因此,您已经编写的代码应该可以很好地让手机使用电话拨号器调用电话。对于平板电脑,您可以使用此方法进行Skype通话:

public static void skype(String number, Context ctx) {
        try {
           Intent sky = new Intent("android.intent.action.VIEW");
            sky.setData(Uri.parse("skype:" + number));
            ctx.startActivity(sky);
        } catch (ActivityNotFoundException e) {
           //Skype not installed
        }

    }

ActivityNotFoundException 可以被捕获,这意味着 Skype 尚未安装。

因此您可以使用此代码将用户带到 Playstore:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.skype.raider" )));

P.S:如果您唯一的要求是确定它是平板电脑还是手机,则上述方法有效。如果您想查找 Sim 是否存在或任何此类内容,您可以使用其他答案中的代码。

关于android - 如果设备是平板电脑,如何打开 Skype,否则进行通话操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22472647/

相关文章:

java - 将 JSONObject 存储到变量中并将它们发送到另一个函数

skype - 使用 Skype 录制音频通话?

IOS调用号码并输入代码

c# - ListView 项目绑定(bind)

android - 使用 VideoView,如何去除 "can' t play this video”的提示信息?

c# - 在 Bot Framework 中获取 Skype 身份?

python - 是否有用于电话调用的免费 python 库?

android - 阻止来电

java - 在 Android 中从 BroadcastReceiver 的 onReceive() 启动应用程序

twilio - 从 Twilio 调用 Skype ID?