How to make a call with Qt directly from the application?

前端 未结 2 1100
囚心锁ツ
囚心锁ツ 2020-12-30 17:42

I want to implement a dialer-feature in my app. Actually, it\'s done, but it works the way I don\'t want to. When button is pressed, native dialer opens and waiting for pres

2条回答
  •  青春惊慌失措
    2020-12-30 17:53

    you will need the permission

    
    

    in your AndroidManifest.xml

    in java you would then do:

    Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:+1123123"));
    startActivity(dialIntent);
    

    the equivalent Qt code is something like:

    QAndroidJniObject action    = QAndroidJniObject::fromString("android.intent.action.CALL");
    QAndroidJniObject uriString = QAndroidJniObject::fromString("tel:+1123123");
    QAndroidJniObject uri       = QAndroidJniObject::callStaticObjectMethod("android/net/Uri", "parse", "(Ljava/lang/String)V", uriString);
    
    
    QAndroidJniObject intent("android/content/Intent","(Ljava/lang/String, Landroid/net/Uri)V", action, uri);
    
    
    QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
    activity.callObjectMethod("startActivity","(Landroid/content/Intent;)V",intent.object());
    

    however, note that using ACTION_CALL may get you reject from the appstore, and google advises to use ACTION_DIAL, which opens the dialer instead of doing a direct call.

提交回复
热议问题