Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- echo 'value of a variable string named cmd' | xclip -selection clipboard
- String a="echo '";
- String c="' | xclip -selection clipboard";
- String cmd=a+clip+b;
- channelSsh.setCommand(cmd);
- package com.quickclip.panky.quickclip;
- import android.app.Activity;
- import android.content.ClipData;
- import android.content.ClipboardManager;
- import android.content.Context;
- import android.os.AsyncTask;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.WindowManager;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import com.jcraft.jsch.ChannelExec;
- import com.jcraft.jsch.JSch;
- import com.jcraft.jsch.Session;
- import java.io.ByteArrayOutputStream;
- import java.util.Properties;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- EditText e1;
- Button b1,b2,b3;
- TextView t1,t2;
- Activity activity = this;
- static int flag=2,time=3000;
- static ClipData clip=null;
- String output;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- e1 = (EditText) findViewById(R.id.editText);
- t1 = (TextView) findViewById(R.id.textView);
- t2 = (TextView) findViewById(R.id.textView3);
- b1 = (Button) findViewById(R.id.button1);
- b2 = (Button) findViewById(R.id.button2);
- b3 = (Button) findViewById(R.id.button3);
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
- b1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- CopyMethod();
- }
- });
- b2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- VolDown();
- }
- });
- b3.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- CopyPace();
- }
- });
- Runnable myRunnable = new Runnable() {
- @Override
- public void run() {
- while (true) {
- if (flag % 2 == 0) {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- } else if (flag % 2 != 0) {
- try {
- Thread.sleep(800);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- activity.runOnUiThread(new Runnable() {
- public void run() {
- CopyMethod();
- flag += 1;
- }
- });
- }
- }
- };
- Thread myThread = new Thread(myRunnable);
- myThread.start();
- }
- public void VolDown(View view) {VolDown();}
- public void CopyPace(View view) {CopyPace();}
- public void ManCopy(View view) {CopyMethod();}
- public void VolDown() {
- ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
- ClipData clip = ClipData.newPlainText("Copied Text","decrease volume");
- clipboard.setPrimaryClip(clip);
- }
- public void CopyPace() {
- if(time==5000) time=2000;
- else if(time<5000) time+=1000;
- t1.setText("Automatically Sending in: "+(time/1000)+" sec");
- }
- public void CopyMethod() {
- ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
- ClipData clip = ClipData.newPlainText("Copied Text", (CharSequence) e1.getText().toString());
- clipboard.setPrimaryClip(clip);
- new AsyncTask<Integer, Void, Void>(){
- @Override
- protected Void doInBackground(Integer... params) {
- try {
- output=executeRemoteCommand();
- t2.setText(output);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- }.execute(1);
- e1.setText("");
- }
- public static String executeRemoteCommand()
- throws Exception {
- String username="pi";
- String password="10<,mmXLSQ";
- String hostname="192.168.43.41";
- int port=22;
- String a="echo '",c="' | xclip -selection clipboard";
- JSch jsch = new JSch();
- Session session = jsch.getSession(username, hostname, port);
- session.setPassword(password);
- // Avoid asking for key confirmation
- Properties prop = new Properties();
- prop.put("StrictHostKeyChecking", "no");
- session.setConfig(prop);
- session.connect();
- // SSH Channel
- ChannelExec channelSsh = (ChannelExec)
- session.openChannel("shell");
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- channelSsh.setOutputStream(baos);
- // Execute command
- String cmd=a+clip+c;
- channelSsh.setCommand(cmd);
- channelSsh.connect();
- channelSsh.disconnect();
- return baos.toString();
- }
- @Override
- public void onClick(View view) {CopyMethod();VolDown();CopyPace();}
- }
- <?xml version="1.0" encoding="utf-8"?>
- <android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.quickclip.panky.quickclip.MainActivity">
- <EditText
- android:id="@+id/editText"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="30dp"
- android:ems="100"
- android:inputType="textAutoCorrect" />
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_below="@+id/editText"
- android:text="Send it Now"
- android:onClick="ManCopy"/>
- <Button
- android:id="@+id/button2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentStart="true"
- android:layout_below="@+id/editText"
- android:text="Volume Down"
- android:onClick="VolDown"/>
- <Button
- android:id="@+id/button3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/editText"
- android:layout_centerHorizontal="true"
- android:text="Switch Pace"
- android:onClick="CopyPace"/>
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/button"
- android:layout_centerHorizontal="true"
- android:textSize="20dp"
- android:layout_marginTop="130dp"
- android:text="Automatically Sending in: 3 sec" />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/textView"
- android:layout_centerHorizontal="true"
- android:textSize="20dp"
- android:text="Speak/Type in this time" />
- <TextView
- android:id="@+id/textView3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/textView2"
- android:layout_centerHorizontal="true"
- android:textSize="20dp"
- android:text="Connecting to SSH" />
- </android.widget.RelativeLayout>
Add Comment
Please, Sign In to add comment