2017-02-17 75 views
0

,我們可以在手機使用以下命令打開聯繫人列表撥打一個號碼:亞行通過其聯繫人姓名

adb shell am start -a android.intent.action.VIEW content://contacts/people/ 

特定聯繫人ID打開

adb shell am start -a android.intent.action.VIEW content://contacts/people/1 

1末是聯繫人的聯繫人ID

我們可以使用以下命令調用定義的號碼:

adb shell am start -a android.intent.action.CALL -d tel:+XXXXXXXXXXXXX 

我們可以選擇聯繫人列表中的預定義聯繫人並撥打電話嗎? 就像我已經有Test_1聯繫人在我的手機中我想打電話給它。如何爲此編寫命令?

回答

0

adb shell命令通過查找電話號碼最新Android版本中的聯繫人姓名是:

content query --uri content://com.android.contacts/data --where 'mimetype="vnd.android.cursor.item/phone_v2" and display_name="<name>"' --projection data4 | cut -d= -f2 

您可以輕鬆地將它與撥號命令:

am start -a android.intent.action.CALL -d tel:$(content query --uri content://com.android.contacts/data --where 'mimetype="vnd.android.cursor.item/phone_v2" and display_name="Test_1"' --projection data4 | cut -d= -f2) 

你沒有提到你的主機操作系統 - 所以它是由你來找出正確的逃逸你需要從你的PC運行此命令

+0

它說切是無法識別的命令 –

+0

我正在研究windows –

1

目前沒有直接的方法可以通過電話簿按名稱聯繫聯繫人。 這是這樣,你可以可以通過自定義應用程序,你會從亞行殼被稱爲

示例應用程序來做到這一點,請授予許可手動,因爲我沒有執行權限的處理和多個號碼查詢

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="call.phonebook"> 

    <uses-permission android:name="android.permission.CALL_PHONE" /> 
    <uses-permission android:name="android.permission.READ_CONTACTS"/> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <action android:name="call.phonebook.BY_NAME" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

和MainActivity

public class MainActivity extends AppCompatActivity { 
    private static final int REQUEST_PERMISSIONS = 100; 
    private String contactNumber; 
    private Uri data, uriContact; 
    private Intent intent; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     intent = getIntent(); 
     data = getIntent().getData(); 

     if (data != null && intent.getAction() != null) { 
      makeCall(); 
     } else { 
      finish(); 
     } 
    } 

    private void makeCall() { 
     data = intent.getData(); 
     String action = intent.getAction(); 
     if (data != null && action != null) { 
      String name = data.getSchemeSpecificPart(); 
      contactNumber = retrieveContactNumber(name); 
      Intent callIntent = new Intent(Intent.ACTION_CALL); 
      callIntent.setData(Uri.parse("tel:" + contactNumber)); 
      // TODO handle permissions 
      if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { 
       return; 
      } 
      startActivity(callIntent); 
     } else { 
      finish(); 
     } 
    } 
    private String retrieveContactNumber(String name) { 
     String contactNumber = null; 
     ContentResolver cr = getContentResolver(); 
     Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, "DISPLAY_NAME = '" + name + "'", null, null); 
     if (cursor.moveToFirst()) { 
      String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)); 
      Cursor phones = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, 
        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); 
      // TODO handle multiple numbers 
      while (phones.moveToNext()) { 
       contactNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 
      } 
      phones.close(); 
     } 
     cursor.close(); 
     return contactNumber; 
    } 
} 

ħ ERE是呼籲終端

adb shell am start 
-n "call.phonebook/call.phonebook.MainActivity" 
-a call.phonebook.BY_NAME -d name:Test 

測試是保存在電話本

我的情況跟

讓我知道這是否會爲工作,你

相關問題