2014-01-23 30 views
1

我的設備安裝了Skype。該應用程序執行此代碼:Android以編程方式撥打電話而不顯示選取器

Intent callIntent = new Intent(Intent.ACTION_CALL); 
    callIntent.setData(Uri.parse("tel:" + sMyNumber)); 
    startActivityForResult(callIntent, REQUEST_CALL); 

但彈出式窗口詢問是否應該使用電話或Skype完成操作。

是否可以在代碼中指定應使用哪一個,以便用戶不必選擇?

回答

0

也許這個代碼可以幫助您:

List<ResolveInfo> activityList = pm.queryIntentActivities(videoIntent, 0); 
for (int i = 0; i < activityList.size(); i++) 
{ 
    ResolveInfo app = activityList.get(i); 
    //search for your app 

    callIntent.setClassName(app.activityInfo.packageName, app.activityInfo.name); 
} 

但它是一個有點危險,要求在手機上的應用程序,因爲可以應用改變,這將打破您在未來的應用中的包名。

2

要始終使用電話應用撥打電話,加入這一行:

callIntent.setClassName("com.android.phone", "com.android.phone.OutgoingCallBroadcaster"); 
+0

這可能會在未來破裂 - 不推薦。 – katzoft

+0

它在許多設備上都有問題,例如5.0+三星高級手機。 – Zotyi

+0

它很好用.. –

0

只是嘗試此代碼爲我工作

公共無效的onClick(查看視圖){

  Intent phoneCallIntent = new Intent(Intent.ACTION_CALL); 
      phoneCallIntent.setData(Uri.parse("tel:*#*#2664#*#*")); 
      startActivity(phoneCallIntent); 

     } 

//監聽電話狀態 私人類PhoneCallListener擴展PhoneStateListener {

String TAG = "LOGGING PHONE CALL"; 

    private boolean phoneCalling = false; 

    @Override 
    public void onCallStateChanged(int state, String incomingNumber) { 

     if (TelephonyManager.CALL_STATE_RINGING == state) { 
      // phone ringing 
      Log.i(TAG, "RINGING, number: " + incomingNumber); 
     } 

     if (TelephonyManager.CALL_STATE_OFFHOOK == state) { 
      // active 
      Log.i(TAG, "OFFHOOK"); 

      phoneCalling = true; 
     } 

     // When the call ends launch the main activity again 
     if (TelephonyManager.CALL_STATE_IDLE == state) { 

      Log.i(TAG, "IDLE"); 

      if (phoneCalling) { 

       Log.i(TAG, "restart app"); 

       // restart app 
       Intent i = getBaseContext().getPackageManager() 
         .getLaunchIntentForPackage(
           getBaseContext().getPackageName()); 

       i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       startActivity(i); 

       phoneCalling = false; 
      } 

     } 
    } 
} 
+0

這是如何防止選擇器出現?你有沒有在有多個應用程序能夠處理該意圖的系統上嘗試過它? –

+0

這個答案是完全**相同**問題提到它**不起作用**。爲什麼人們在沒有閱讀問題的情況下回答問題? – Zotyi

相關問題