ADB command to push stream / image to camera












0















i need to write a java code to execute some command for automation purpose.
what i want to achieve is pushing image to camera.



i tried to write a code to input text via adb and it works.. it looks like this



public void inputTextByCode(String deviceId, String input) throws IOException{  
welcomeTheTester();
String commandStr = "input keyboard text ";

Process process = null;
String commandString = "";
if(deviceId != null) {
commandString = String.format("%s", "adb -s " + deviceId + " shell " + commandStr + input);
} else {
commandString = String.format("%s", "adb shell " + commandStr + input);
}

System.out.print("Command is "+commandString+"n");
try {
process = ProcessHelper.runTimeExec(commandString);
} catch (IOException e) {
}
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.print(line+"n");
}
}


it will produce adb command as



adb -s 192.168.28.101:5555 shell input keyboard text testing


could i do the same,, but with camera? how could i push image / some kind of stream to android camera?










share|improve this question

























  • Hi, Are you able to connect to camera with adb commands.? If yes.. you have to issue a command adb -s <ip addess>:<port number> push <file path> /sdcard/

    – nkalra0123
    Nov 23 '18 at 10:39













  • @nkalra0123 unfortunately not, so i want to automate an app which is a built in camera feature, to scan qr codes

    – thekucays
    Nov 23 '18 at 10:43











  • sorry, unable to understand. Are you working with an Android camera, or with an app on the mobile phone which has a camera feature.?

    – nkalra0123
    Nov 23 '18 at 11:05











  • @nkalra0123 on an app that has camera feature exactly.. is that possible to push the image in that situation?

    – thekucays
    Nov 23 '18 at 11:26











  • If you have an app, then why do you want to push the image, just save the image from your java code. check this question stackoverflow.com/questions/8588838/…

    – nkalra0123
    Nov 23 '18 at 11:29
















0















i need to write a java code to execute some command for automation purpose.
what i want to achieve is pushing image to camera.



i tried to write a code to input text via adb and it works.. it looks like this



public void inputTextByCode(String deviceId, String input) throws IOException{  
welcomeTheTester();
String commandStr = "input keyboard text ";

Process process = null;
String commandString = "";
if(deviceId != null) {
commandString = String.format("%s", "adb -s " + deviceId + " shell " + commandStr + input);
} else {
commandString = String.format("%s", "adb shell " + commandStr + input);
}

System.out.print("Command is "+commandString+"n");
try {
process = ProcessHelper.runTimeExec(commandString);
} catch (IOException e) {
}
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.print(line+"n");
}
}


it will produce adb command as



adb -s 192.168.28.101:5555 shell input keyboard text testing


could i do the same,, but with camera? how could i push image / some kind of stream to android camera?










share|improve this question

























  • Hi, Are you able to connect to camera with adb commands.? If yes.. you have to issue a command adb -s <ip addess>:<port number> push <file path> /sdcard/

    – nkalra0123
    Nov 23 '18 at 10:39













  • @nkalra0123 unfortunately not, so i want to automate an app which is a built in camera feature, to scan qr codes

    – thekucays
    Nov 23 '18 at 10:43











  • sorry, unable to understand. Are you working with an Android camera, or with an app on the mobile phone which has a camera feature.?

    – nkalra0123
    Nov 23 '18 at 11:05











  • @nkalra0123 on an app that has camera feature exactly.. is that possible to push the image in that situation?

    – thekucays
    Nov 23 '18 at 11:26











  • If you have an app, then why do you want to push the image, just save the image from your java code. check this question stackoverflow.com/questions/8588838/…

    – nkalra0123
    Nov 23 '18 at 11:29














0












0








0








i need to write a java code to execute some command for automation purpose.
what i want to achieve is pushing image to camera.



i tried to write a code to input text via adb and it works.. it looks like this



public void inputTextByCode(String deviceId, String input) throws IOException{  
welcomeTheTester();
String commandStr = "input keyboard text ";

Process process = null;
String commandString = "";
if(deviceId != null) {
commandString = String.format("%s", "adb -s " + deviceId + " shell " + commandStr + input);
} else {
commandString = String.format("%s", "adb shell " + commandStr + input);
}

System.out.print("Command is "+commandString+"n");
try {
process = ProcessHelper.runTimeExec(commandString);
} catch (IOException e) {
}
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.print(line+"n");
}
}


it will produce adb command as



adb -s 192.168.28.101:5555 shell input keyboard text testing


could i do the same,, but with camera? how could i push image / some kind of stream to android camera?










share|improve this question
















i need to write a java code to execute some command for automation purpose.
what i want to achieve is pushing image to camera.



i tried to write a code to input text via adb and it works.. it looks like this



public void inputTextByCode(String deviceId, String input) throws IOException{  
welcomeTheTester();
String commandStr = "input keyboard text ";

Process process = null;
String commandString = "";
if(deviceId != null) {
commandString = String.format("%s", "adb -s " + deviceId + " shell " + commandStr + input);
} else {
commandString = String.format("%s", "adb shell " + commandStr + input);
}

System.out.print("Command is "+commandString+"n");
try {
process = ProcessHelper.runTimeExec(commandString);
} catch (IOException e) {
}
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.print(line+"n");
}
}


it will produce adb command as



adb -s 192.168.28.101:5555 shell input keyboard text testing


could i do the same,, but with camera? how could i push image / some kind of stream to android camera?







android automation android-emulator automated-tests adb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 18:22







thekucays

















asked Nov 23 '18 at 10:11









thekucaysthekucays

1642216




1642216













  • Hi, Are you able to connect to camera with adb commands.? If yes.. you have to issue a command adb -s <ip addess>:<port number> push <file path> /sdcard/

    – nkalra0123
    Nov 23 '18 at 10:39













  • @nkalra0123 unfortunately not, so i want to automate an app which is a built in camera feature, to scan qr codes

    – thekucays
    Nov 23 '18 at 10:43











  • sorry, unable to understand. Are you working with an Android camera, or with an app on the mobile phone which has a camera feature.?

    – nkalra0123
    Nov 23 '18 at 11:05











  • @nkalra0123 on an app that has camera feature exactly.. is that possible to push the image in that situation?

    – thekucays
    Nov 23 '18 at 11:26











  • If you have an app, then why do you want to push the image, just save the image from your java code. check this question stackoverflow.com/questions/8588838/…

    – nkalra0123
    Nov 23 '18 at 11:29



















  • Hi, Are you able to connect to camera with adb commands.? If yes.. you have to issue a command adb -s <ip addess>:<port number> push <file path> /sdcard/

    – nkalra0123
    Nov 23 '18 at 10:39













  • @nkalra0123 unfortunately not, so i want to automate an app which is a built in camera feature, to scan qr codes

    – thekucays
    Nov 23 '18 at 10:43











  • sorry, unable to understand. Are you working with an Android camera, or with an app on the mobile phone which has a camera feature.?

    – nkalra0123
    Nov 23 '18 at 11:05











  • @nkalra0123 on an app that has camera feature exactly.. is that possible to push the image in that situation?

    – thekucays
    Nov 23 '18 at 11:26











  • If you have an app, then why do you want to push the image, just save the image from your java code. check this question stackoverflow.com/questions/8588838/…

    – nkalra0123
    Nov 23 '18 at 11:29

















Hi, Are you able to connect to camera with adb commands.? If yes.. you have to issue a command adb -s <ip addess>:<port number> push <file path> /sdcard/

– nkalra0123
Nov 23 '18 at 10:39







Hi, Are you able to connect to camera with adb commands.? If yes.. you have to issue a command adb -s <ip addess>:<port number> push <file path> /sdcard/

– nkalra0123
Nov 23 '18 at 10:39















@nkalra0123 unfortunately not, so i want to automate an app which is a built in camera feature, to scan qr codes

– thekucays
Nov 23 '18 at 10:43





@nkalra0123 unfortunately not, so i want to automate an app which is a built in camera feature, to scan qr codes

– thekucays
Nov 23 '18 at 10:43













sorry, unable to understand. Are you working with an Android camera, or with an app on the mobile phone which has a camera feature.?

– nkalra0123
Nov 23 '18 at 11:05





sorry, unable to understand. Are you working with an Android camera, or with an app on the mobile phone which has a camera feature.?

– nkalra0123
Nov 23 '18 at 11:05













@nkalra0123 on an app that has camera feature exactly.. is that possible to push the image in that situation?

– thekucays
Nov 23 '18 at 11:26





@nkalra0123 on an app that has camera feature exactly.. is that possible to push the image in that situation?

– thekucays
Nov 23 '18 at 11:26













If you have an app, then why do you want to push the image, just save the image from your java code. check this question stackoverflow.com/questions/8588838/…

– nkalra0123
Nov 23 '18 at 11:29





If you have an app, then why do you want to push the image, just save the image from your java code. check this question stackoverflow.com/questions/8588838/…

– nkalra0123
Nov 23 '18 at 11:29












1 Answer
1






active

oldest

votes


















0














You have to create a dummy camera app. Most app which require image capture from camera implement this logic.



Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}


and implement this code to get the image from camera.



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);
}
}


So, you have to create a dummy camera app which should have an Activity like this



<activity
android:name="com.android.camera.CaptureActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Camera"
android:configChanges="orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>


and you should return something like this.



Bitmap bitmap = CameraUtil.makeBitmap(data, 50 * 1024);
bitmap = CameraUtil.rotate(bitmap, orientation);
Log.v(TAG, "inlined bitmap into capture intent result");
mActivity.setResultEx(Activity.RESULT_OK,
Intent("inline-data").putExtra("data", bitmap));
mActivity.finish();


In this way your QR code scanner app will think it has opened a legit camera app, but your dummy app will be opened, and your app will return the image which you want






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444658%2fadb-command-to-push-stream-image-to-camera%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You have to create a dummy camera app. Most app which require image capture from camera implement this logic.



    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
    startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }


    and implement this code to get the image from camera.



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
    Bundle extras = data.getExtras();
    Bitmap imageBitmap = (Bitmap) extras.get("data");
    mImageView.setImageBitmap(imageBitmap);
    }
    }


    So, you have to create a dummy camera app which should have an Activity like this



    <activity
    android:name="com.android.camera.CaptureActivity"
    android:label="@string/app_name"
    android:theme="@style/Theme.Camera"
    android:configChanges="orientation|screenSize|keyboardHidden"
    android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
    <intent-filter>
    <action android:name="android.media.action.IMAGE_CAPTURE" />
    <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    </activity>


    and you should return something like this.



    Bitmap bitmap = CameraUtil.makeBitmap(data, 50 * 1024);
    bitmap = CameraUtil.rotate(bitmap, orientation);
    Log.v(TAG, "inlined bitmap into capture intent result");
    mActivity.setResultEx(Activity.RESULT_OK,
    Intent("inline-data").putExtra("data", bitmap));
    mActivity.finish();


    In this way your QR code scanner app will think it has opened a legit camera app, but your dummy app will be opened, and your app will return the image which you want






    share|improve this answer




























      0














      You have to create a dummy camera app. Most app which require image capture from camera implement this logic.



      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
      startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
      }


      and implement this code to get the image from camera.



      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
      Bundle extras = data.getExtras();
      Bitmap imageBitmap = (Bitmap) extras.get("data");
      mImageView.setImageBitmap(imageBitmap);
      }
      }


      So, you have to create a dummy camera app which should have an Activity like this



      <activity
      android:name="com.android.camera.CaptureActivity"
      android:label="@string/app_name"
      android:theme="@style/Theme.Camera"
      android:configChanges="orientation|screenSize|keyboardHidden"
      android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
      <intent-filter>
      <action android:name="android.media.action.IMAGE_CAPTURE" />
      <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
      </activity>


      and you should return something like this.



      Bitmap bitmap = CameraUtil.makeBitmap(data, 50 * 1024);
      bitmap = CameraUtil.rotate(bitmap, orientation);
      Log.v(TAG, "inlined bitmap into capture intent result");
      mActivity.setResultEx(Activity.RESULT_OK,
      Intent("inline-data").putExtra("data", bitmap));
      mActivity.finish();


      In this way your QR code scanner app will think it has opened a legit camera app, but your dummy app will be opened, and your app will return the image which you want






      share|improve this answer


























        0












        0








        0







        You have to create a dummy camera app. Most app which require image capture from camera implement this logic.



        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }


        and implement this code to get the image from camera.



        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(imageBitmap);
        }
        }


        So, you have to create a dummy camera app which should have an Activity like this



        <activity
        android:name="com.android.camera.CaptureActivity"
        android:label="@string/app_name"
        android:theme="@style/Theme.Camera"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
        <intent-filter>
        <action android:name="android.media.action.IMAGE_CAPTURE" />
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </activity>


        and you should return something like this.



        Bitmap bitmap = CameraUtil.makeBitmap(data, 50 * 1024);
        bitmap = CameraUtil.rotate(bitmap, orientation);
        Log.v(TAG, "inlined bitmap into capture intent result");
        mActivity.setResultEx(Activity.RESULT_OK,
        Intent("inline-data").putExtra("data", bitmap));
        mActivity.finish();


        In this way your QR code scanner app will think it has opened a legit camera app, but your dummy app will be opened, and your app will return the image which you want






        share|improve this answer













        You have to create a dummy camera app. Most app which require image capture from camera implement this logic.



        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }


        and implement this code to get the image from camera.



        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(imageBitmap);
        }
        }


        So, you have to create a dummy camera app which should have an Activity like this



        <activity
        android:name="com.android.camera.CaptureActivity"
        android:label="@string/app_name"
        android:theme="@style/Theme.Camera"
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
        <intent-filter>
        <action android:name="android.media.action.IMAGE_CAPTURE" />
        <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </activity>


        and you should return something like this.



        Bitmap bitmap = CameraUtil.makeBitmap(data, 50 * 1024);
        bitmap = CameraUtil.rotate(bitmap, orientation);
        Log.v(TAG, "inlined bitmap into capture intent result");
        mActivity.setResultEx(Activity.RESULT_OK,
        Intent("inline-data").putExtra("data", bitmap));
        mActivity.finish();


        In this way your QR code scanner app will think it has opened a legit camera app, but your dummy app will be opened, and your app will return the image which you want







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 12 '18 at 10:37









        nkalra0123nkalra0123

        791510




        791510
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444658%2fadb-command-to-push-stream-image-to-camera%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini