2016-04-08 17 views
0

我想從我的應用程序中以編程方式輸入「enter」鍵事件。無法在我的應用程序內輸入「enter」鍵事件android

我已經嘗試過使用abd shell命令以及使用AccessibilityService,但發現它沒有運氣。

Similar question was asked here as well

下面是我的代碼,我用來執行ADB shell命令:

try { 
    Runtime runtime = Runtime.getRuntime(); 

    Process p = runtime.exec("input keyevent 66"); 

    BufferedReader standardIn = new BufferedReader(new InputStreamReader(p.getInputStream())); 
    BufferedReader errorIn = new BufferedReader(new InputStreamReader(p.getErrorStream())); 

    String output = ""; 
    String line; 
    while ((line = standardIn.readLine()) != null) { 
     output += line + "\n"; 
    } 
    while ((line = errorIn.readLine()) != null) { 
     output += line + "\n"; 
    } 

    Log.d("output", "" + output); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

我得到以下輸出:

sh: resetreason: can't execute: Permission denied 

有人請幫助我。

如果有人知道如何使用AccessibilityService實現它,請讓我知道。

在此先感謝!

回答

-1

加這個<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />權限&再試一次。

+0

添加了上述權限,但仍然引發相同的輸出錯誤。 – Wazz

+0

我認爲上面的權限和上面的代碼只適用於根目錄的設備。 – Wazz

相關問題