大爷闪亮登场 發表於 2019-11-30 14:32:00

uni-app拨打电话

<p>调起通讯页面拨打电话</p>
<p>https://uniapp.dcloud.io/api/system/phone?id=makephonecall</p>
<p>点击按钮直接拨打电话</p>
<div class="cnblogs_code">
<pre>&lt;template&gt;
    &lt;view&gt;
      &lt;text @tap=<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">makePhone</span><span style="color: rgba(128, 0, 0, 1)">"</span>&gt;拨打电话&lt;/text&gt;
    &lt;/view&gt;
&lt;/template&gt;</pre>
</div>
<p>&nbsp;</p>
<div class="cnblogs_code">
<pre>&lt;script&gt;<span style="color: rgba(0, 0, 0, 1)">
    export </span><span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)">{
      data(){
            </span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">{
                phone:</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">110010</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
            }
      },
      methods:{
            </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 点击拨打电话</span>
<span style="color: rgba(0, 0, 0, 1)">            makePhone(){
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 导入Activity、Intent类</span>
                <span style="color: rgba(0, 0, 255, 1)">var</span> Intent = plus.android.importClass(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">android.content.Intent</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
                </span><span style="color: rgba(0, 0, 255, 1)">var</span> Uri = plus.android.importClass(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">android.net.Uri</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">);
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 获取主Activity对象的实例</span>
                <span style="color: rgba(0, 0, 255, 1)">var</span> main =<span style="color: rgba(0, 0, 0, 1)"> plus.android.runtimeMainActivity();
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 创建Intent</span>
                <span style="color: rgba(0, 0, 255, 1)">var</span> uri = Uri.parse(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">tel:</span><span style="color: rgba(128, 0, 0, 1)">"</span>+<span style="color: rgba(0, 0, 255, 1)">this</span>.phone); <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 这里可修改电话号码</span>
                <span style="color: rgba(0, 0, 255, 1)">var</span> call = <span style="color: rgba(0, 0, 255, 1)">new</span> Intent(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">android.intent.action.CALL</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">,uri);
                </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 调用startActivity方法拨打电话</span>
<span style="color: rgba(0, 0, 0, 1)">                main.startActivity( call );
            },<br>       
      }
    }
</span>&lt;/script&gt;</pre>
</div><br><br>
来源:https://www.cnblogs.com/angenstern/p/11962421.html
頁: [1]
查看完整版本: uni-app拨打电话