Created
November 6, 2018 16:03
-
-
Save SamuelTulach/db264187e51ea4291dbe2d7c760a4c6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.samueltulach.vibraswitch; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Switch; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.OutputStream; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
public void Disable(View v) { | |
try { | |
String line; | |
Process process = Runtime.getRuntime().exec("su"); | |
OutputStream stdin = process.getOutputStream(); | |
InputStream stderr = process.getErrorStream(); | |
InputStream stdout = process.getInputStream(); | |
stdin.write(("echo 0 > /sys/class/timed_output/vibrator/vtg_level\n").getBytes()); | |
stdin.write("exit\n".getBytes()); | |
stdin.flush(); | |
stdin.close(); | |
BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); | |
while ((line = br.readLine()) != null) { | |
Log.d("[Output]", line); | |
} | |
br.close(); | |
br = new BufferedReader(new InputStreamReader(stderr)); | |
while ((line = br.readLine()) != null) { | |
Log.e("[Error]", line); | |
} | |
br.close(); | |
process.waitFor(); | |
process.destroy(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
AlertDialog.Builder builder1 = new AlertDialog.Builder(this); | |
builder1.setMessage("Error!"); | |
AlertDialog alert11 = builder1.create(); | |
alert11.show(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
AlertDialog.Builder builder1 = new AlertDialog.Builder(this); | |
builder1.setMessage("Error!"); | |
AlertDialog alert11 = builder1.create(); | |
alert11.show(); | |
} | |
} | |
public void Enable(View v) { | |
try { | |
String line; | |
Process process = Runtime.getRuntime().exec("su"); | |
OutputStream stdin = process.getOutputStream(); | |
InputStream stderr = process.getErrorStream(); | |
InputStream stdout = process.getInputStream(); | |
stdin.write(("echo 2900 > /sys/class/timed_output/vibrator/vtg_level\n").getBytes()); | |
stdin.write("exit\n".getBytes()); | |
stdin.flush(); | |
stdin.close(); | |
BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); | |
while ((line = br.readLine()) != null) { | |
Log.d("[Output]", line); | |
} | |
br.close(); | |
br = new BufferedReader(new InputStreamReader(stderr)); | |
while ((line = br.readLine()) != null) { | |
Log.e("[Error]", line); | |
} | |
br.close(); | |
process.waitFor(); | |
process.destroy(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
AlertDialog.Builder builder1 = new AlertDialog.Builder(this); | |
builder1.setMessage("Error!"); | |
AlertDialog alert11 = builder1.create(); | |
alert11.show(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
AlertDialog.Builder builder1 = new AlertDialog.Builder(this); | |
builder1.setMessage("Error!"); | |
AlertDialog alert11 = builder1.create(); | |
alert11.show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment