我是android編程的新手。我正在嘗試編寫一個簡單的應用程序,使用另一個Android應用程序切換硬件開關。另一個android應用程序的屏幕操作
我寫了啓動第二個應用程序的代碼。現在我需要在肖像模式下點擊屏幕頂部的可點擊區域,然後在結果屏幕中以縱向模式點擊靠近頂部的另一個可點擊區域。這將切換開關。第一個屏幕帶有可點擊區域的文字,但第二個屏幕沒有。
到目前爲止,我一直無法弄清楚如何從我的應用程序中訪問第二個應用程序的當前屏幕布局。此外,我需要知道如何從我的應用程序點擊屏幕上的可點擊區域。我有第二個應用程序的SDK供參考。
這兩個應用程序都運行在Android平板電腦上。如果有人能指點我一些互聯網資源或一些簡單的代碼片段來幫助我理解如何完成這項任務,我將非常感激。 (我做了自己的研究,但作爲一個新手,它很難快速理解和實現。)另外,任何關於從我的應用程序執行此操作的更簡單方法的建議或建議都將不勝感激。我需要這個代碼來處理一個沒有固定的android設備。
這裏是我到目前爲止的代碼:
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.me.testapplication">
<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" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity:
package com.example.me.testapplication;
import android.content.Intent;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import static com.example.me.testapplication.R.id.button1;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button Button1 = (Button) findViewById(button1);
Button1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(package);
startActivity(launchIntent);
}
}
在Python,我可以簡單地使用下面的代碼行點擊所需區域的屏幕,但我不知道如何完成這從我的android studio項目。
os.system('adb shell input tap x y')
任何指向解決方案的指針都將不勝感激。