2016-11-08 88 views
2

我正在嘗試執行ConnectionService。爲此,我需要在TelecomService上註冊一個電話帳戶,以便設備知道它可以使用我的應用程序撥打電話。Android ConnectionService - SecurityException在註冊電話帳戶時

當我嘗試註冊一個手機賬戶中,我得到一個SecurityException:包com.xxx.xxx不屬於10145.

我缺少什麼?以下是註冊電話帳戶的代碼。 (我已經添加了許可清單等)

PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(new ComponentName("com.mypackage", "com.mypackage.MyConnectionService", "my_phoneHandleId"); 
PhoneAccount.Builder builder   = PhoneAccount.builder(phoneAccountHandle, "Custom label"); 

builder.setCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT | PhoneAccount.CAPABILITY_CONNECTION_MANAGER); 
builder.addSupportedUriScheme("my_scheme"); 
builder.setAddress(Uri.parse("my_scheme://" + "customNumber")); 

PhoneAccount phoneAccount = builder.build(); 
telecomService.registerPhoneAccount(phoneAccount); 

回答

1

也許你忘了申報權限:

android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE" 

照顧請求此權限MARSHMELLOW和更高的Android版本。 Requesting Permissions at Run Time

// Here, thisActivity is the current activity 
if (ContextCompat.checkSelfPermission(thisActivity, 
       Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE) 
     != PackageManager.PERMISSION_GRANTED) { 

    // Should we show an explanation? 
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, 
      Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE)) { 

     // Show an expanation to the user *asynchronously* -- don't block 
     // this thread waiting for the user's response! After the user 
     // sees the explanation, try again to request the permission. 

    } else { 

     // No explanation needed, we can request the permission. 

     ActivityCompat.requestPermissions(thisActivity, 
       new String[]{Manifest.permission.BIND_TELECOM_CONNECTION_SERVICE}, 
       MY_PERMISSIONS_REQUEST_BIND_TELECOM_CONNECTION_SERVICE); 

     // MY_PERMISSIONS_REQUEST_BIND_TELECOM_CONNECTION_SERVICE is an 
     // app-defined int constant. The callback method gets the 
     // result of the request. 
    } 
} 
+1

我已經擁有Android.manifest的權限。我嘗試了請求權限的代碼,但我始終在回調中拒絕了權限。沒有對話提供給用戶。不知道我做錯了什麼。我有targetdk設置爲15,嘗試將其設置爲23,但結果相同。 –

+0

您是否找到解決方案?我陷入了同樣的問題 – Sonal