2017-05-21 6 views
0

Ich kann eine App über meinen Code starten, kann aber keine Touch-Simulation an die Schaltfläche in dieser App senden. Hier ist der Hauptcode. Es gibt keine Fehler beim Kompilieren. Ich hatte verwendet dispatch aber da das nicht funktioniert Ich entfernte esTouch-Ereignis an eine andere Anwendung senden

package com.mycompany.myapp3; 
import android.app.*; 
import android.os.*; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.Button; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.*; 
import android.system.*; 
import android.view.MotionEvent; 
import android.view.InputDevice.*; 
import android.widget.*; 
public class MainActivity extends Activity 
{ 
Button button; 
//static public MotionEvent obtain(long downtime,long eventime,int action,float x,float y,int metastate) 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 

     addListenerOnbutton(); 
    
     simulatepress(-1100,250); 

     MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,400,400,0); 



    } 


public void addListenerOnbutton() { 

button=(Button)findViewById(R.id.button1); 
button.setOnClickListener(new OnClickListener(){ 
@Override 
    public void onClick(View arg0){ 
Intent launchIntent=getPackageManager().getLaunchIntentForPackage("com.abc.xyz"); 
if (launchIntent!=null){ 
startActivity(launchIntent); 
} 

pause1(10000); 
Toast.makeText(getApplicationContext(),"Waiting over",Toast.LENGTH_SHORT).show(); 

    simulatepress(-180,25); 

} 
}); 


} 
@Override 
public boolean dispatchTouchEvent(MotionEvent ev) 
{ 
// TODO: Implement this method 
return super.dispatchTouchEvent(ev); 
} 
    


public void pause1(long sleeptime){ 
try{ 
Thread.sleep(sleeptime); 
} catch (InterruptedException ex){ 

} 
} 


// our program for generating click 
// dont delete 


public void simulatepress(long x,long y){ 
MotionEvent e=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,x,y,0); 
onTouchEvent(e); 
//dispatchTouchEvent(e); 

} 










} 

Antwort

0

Sie ein Root-Methode verwenden:

String x,y = "400" 
String[] deviceCommands = {"su", "input touchscreen tap", x, y}; 
try { 
    Process process = Runtime.getRuntime().exec(deviceCommands); 
} catch (IOException e) { 
    e.printStackTrace(); 
    Toast.makeText(getApplicationContext(), "error!", Toast.LENGTH_SHORT).show(); 
} 

Funktioniert nur mit root. x und y sind die Koordinaten.

Verwandte Themen