Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package example_company.controller1;
- import android.os.AsyncTask;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import com.jcraft.jsch.Channel;
- import com.jcraft.jsch.ChannelExec;
- import com.jcraft.jsch.JSch;
- import com.jcraft.jsch.JSchException;
- import com.jcraft.jsch.Session;
- import android.support.design.widget.CoordinatorLayout;
- import android.support.design.widget.Snackbar;
- import android.graphics.Color;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- public void onClick11 (View v) {
- new AsyncTask<Integer, Void, Void>(){
- @Override
- protected Void doInBackground(Integer... params) {
- try {
- executeSSHcommand();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- }.execute(1);
- }
- public void executeSSHcommand(){
- String user = "pi";
- String password = "raspberry";
- String host = "192.168.0.1";
- int port=22;
- try{
- JSch jsch = new JSch();
- Session session = jsch.getSession(user, host, port);
- session.setPassword(password);
- session.setConfig("StrictHostKeyChecking", "no");
- session.setTimeout(10000);
- session.connect();
- ChannelExec channel = (ChannelExec)session.openChannel("exec");
- channel.setCommand("omxd n");
- channel.connect();
- channel.disconnect();
- }
- catch(JSchException e){
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/activity_main"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="example_company.controller1.MainActivity">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Hello World!" />
- <Button
- android:text="NEXT"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_centerHorizontal="true"
- android:id="@+id/button"
- android:onClick="onCLick11" />
- </RelativeLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="example_company.controller1">
- <uses-permission android:name="android.permission.INTERNET" />
- <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>
Add Comment
Please, Sign In to add comment