2017-09-12 29 views
0

我認爲問題有點瘋狂,我基本上想從我的應用程序發送滾動事件到另一個應用程序(例如鉻)。所以基本上,如果chrome打開,並且當用戶按下向上或向下按鈕時,我的後臺活動會監聽該按鈕事件,如果它是向上事件,則會向上或向下滾動Chrome瀏覽器打開的網頁。我不確定是否有可能,因爲我正在通過Google的一些文檔進行閱讀,並且我們需要root權限才能將事件從一個應用程序發送到另一個應用程序。我還沒有任何代碼。所以任何人都知道這可能與android api?發送滾動事件到另一個應用程序

謝謝

+1

在google上尋找「注入事件」和「可訪問性管理器」。 也看起來如何gamepad->觸摸屏事件幫助應用程序,如來自8bitdo的應用程序工作(轉儲它在一個反編譯器)。 –

+0

@LassiKinnunen男人,我在找什麼,再次感謝 – Achayan

回答

1

我無法回答在鉻的上下文中。但是,您基本上可以序列化您需要的內容,並通過意向系統將其發送到其他應用程序。

舉個例子,在你的第一個應用程序時,您會收到觸摸事件

boolean onTouch(MotionEvent event){ 
    if(event.getActionMasked() == MotionEvent.ACTION_UP){ 
     Intent startOtherApplication = new Intent(); 
     startOtherApplication.putExtra("ACTION_UP_X",event.getX()); 
     startOtherApplication.putExtra("ACTION_UP_Y",event.getY()); 
     startOtherApplication.setComponent(new ComponentName("com.your.other.application", "com.your.other.application.ActivityYouWantToHandleTouch")); 
     startActivity(intent); 
    } 
} 

然後將提取您的其他應用程序的活動(ActivityYouWantToHandleTouch)的意圖。

public void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    Intent fetchedIntent = getIntent(); 
    boolean hasUpAction = false;   
    int x = 0; 
    int y = 0;   
    if(fetchedIntent != null){ 
      hasUpAction = (fetchedIntent.getExtra("ACTION_UP_X")!=null); 
      x = fetchedIntent.getExtra("ACTION_UP_X"); 
      y = fetchedIntent.getExtra("ACTION_UP_Y"); 

    } 
} 
相關問題