Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Running adb commands from Android device

Discussion in 'Android' started by saifshk17, Jul 22, 2021.

  1. saifshk17

    saifshk17

    Joined:
    Dec 4, 2016
    Posts:
    488
    Is there a way to run certain adb commands from a Unity application in an android device (C#)?
    The adb commands are such as setting home-activity and reboot device such as:
    Code (CSharp):
    1. adb shell cmd package set-home-activity PackageName/ActivityName
    and
    Code (CSharp):
    1. adb reboot
    For example, it is implemented in Java using Process such as
    Code (CSharp):
    1. Process process = Runtime.getRuntime().exec("your command");
    2. BufferedReader bufferedReader = new BufferedReader(
    3. new InputStreamReader(process.getInputStream()));
    And in Unity I have found out that we can as well call Process as
    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using System.IO;
    4. using System.Diagnostics;
    5.  
    6. public class ProcessScript : MonoBehaviour
    7. {
    8.     Process process = null;
    9. }
    So how do I call the commands in C# as mentioned in java?
     
    Last edited: Jul 22, 2021