简体   繁体   English

Android Wear电话

[英]android wear phone call

I have 2 questions 我有两个问题

  1. Can we make phone calls programatically from Android wear app? 我们可以通过Android Wear应用程序以编程方式拨打电话吗?
  2. I have created a custom notifcation on Android wear app. 我在Android Wear应用上创建了自定义通知 Is it possible to open the mobile dialer app, when user tap on the action on custom notification? 当用户点击自定义通知上的操作时,是否可以打开移动拨号器应用程序?

Any help woud be appreciated. 任何帮助将不胜感激。

Thanks. 谢谢。

yes i thing it is possible. 是的,我有可能。 try to use: 尝试使用:

yes thing it is possible. try to use:

/*start a direct call, make sure you have call permission declared on your manifest
*<uses-permission android:name="android.permission.CALL_PHONE" />
*/
public static void phoneCall(String n, Activity currentActivity) {
    char ench[] = n.toCharArray();
    String tel = "";
    for (int i = 0; i < ench.length; i++) {
        if (ench[i] == '#')
            tel = tel + Uri.encode("#");
        else
            tel = tel + ench[i];
    }
    String toDial = "tel:" + tel;// msgbox(Intent.ACTION_ALL_APPS);
    currentActivity.startActivityForResult(
            new Intent(hasPermission(currentActivity,
                    permission.CALL_PHONE) ? Intent.ACTION_CALL
                    : Intent.ACTION_DIAL, Uri.parse(toDial)), 1024);

}
//open phonne compositor with phone number as n
public static void phoneDial(String n, Activity currentActivity) {
    char ench[] = n.toCharArray();
    String tel = "";
    for (int i = 0; i < ench.length; i++) {
        if (ench[i] == '#')
            tel = tel + Uri.encode("#");
        else
            tel = tel + ench[i];
    }
    String toDial = "tel:" + tel;// msgbox(Intent.ACTION_ALL_APPS);
    Intent intent=new Intent(Intent.ACTION_DIAL,
            Uri.parse(toDial));
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
    currentActivity.startActivityForResult(intent, 1024);

}
//control if your application have some permission
public static boolean hasPermission(Context context, String permission) {
        int res = context.checkCallingOrSelfPermission(permission);
        return (res == PackageManager.PERMISSION_GRANTED);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM