Opening various applications from Android activity and receiving and storing screenshots

I am creating an automation application in which I have to store screenshots of the home page of other applications in real time.

I have the following task statement.

Suppose I have application A and application B. I want my application A to periodically open application B every day at a specified time and detect a screenshot and close this application, and on average when loading screenshots in application A (or on some either server and access to the application A) and create a wise day of recording.

Can you help me in the automation process without using a button?

Key Challenges

  • Scroll from the action in Appendix A to open Appendix B without clicking a button (for example, a scheduler).
  • Taking screenshots at the same time and fetching from the gallery and uploading it to the server.
  • Close this application and return the control to application A as soon as the photos are uploaded to the server.
0
android
Dec 21 '16 at 7:44
source share
2 answers

As the problem states regarding the spy’s intentions, I believe that the solutions I offer are not used to violate the privacy or personal data of potential users.

We will go one by one in accordance with the requirements.

  • Launch another application from your application . You should know the package name of the application you want to open. If you want to make this dynamic. Here is the code to list all the applications installed on the device.

    final PackageManager pm = getPackageManager(); //get a list of installed apps. List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : packages) { Log.d(TAG, "Installed package :" + packageInfo.packageName); Log.d(TAG, "Source dir : " + packageInfo.sourceDir); Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); } 

    The package name that you get here can be used to start the main activity of the corresponding application. Here's the code for it:

     Intent launchIntent = getPackageManager().getLaunchIntentForPackage("Enter package name here"); if (launchIntent != null) { startActivity(launchIntent);//null pointer check in case package name was not found } 
  • Automatic task at periodic intervals . Put this code in your activity where the user set the alarm.

     public void setAlarm(){ BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive( Context context, Intent _ ) { //launch application and screenshot code here context.unregisterReceiver( this ); // this == BroadcastReceiver, not Activity } }; this.registerReceiver( receiver, new IntentFilter("any_custom_message") ); PendingIntent pintent = PendingIntent.getBroadcast( this, 0, new Intent("custom_message_used_above"), 0 ); AlarmManager manager = (AlarmManager)(this.getSystemService( Context.ALARM_SERVICE )); // set alarm to fire 5 sec (1000*5) from now (SystemClock.elapsedRealtime()) manager.set( AlarmManager.RTC_WAKEUP, 10*60*60 //10 minutes in millis, pintent ); } 

    Update manifest for permissions:

     <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission> 
  • Take a screenshot of the open application . This is not possible for the API, as this can lead to privacy issues. We will try this using similar chathead services. They run as a service and use Window to draw widgets and layout. Therefore, the window layout can be used to capture a screenshot. Go to this blog post and learn how to create chats. In this case, there should be no design for the chat, since its main purpose is to capture a screenshot. Now, to take a screenshot, use the following code:

     Bitmap bitmap; View v1 = //Your root layout after inflating to WindowManager v1.setDrawingCacheEnabled(true); bitmap = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); 
  • Saving and sending to the server :

     String mPath = Environment.getExternalStorageDirectory().toString() + "/" + YOUR_DIRECTORY_NAME; OutputStream fout = null; imageFile = new File(mPath); try { fout = new FileOutputStream(imageFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout); fout.flush(); fout.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

    You can use any library, such as Volley or retrofit, to send this file to the server. Here is a link example .

Hope this solves most of the problems with your application. I may have missed some common things, such as allowing read and write files. Please enable them as I did not run the code and did not try.

+1
Dec 21 '16 at 22:04
source share

You can use the following approach

  • Create a sticky service.
  • Create a combination in PendingIntent + AlarmManager that will run the above service every day in normal mode.
  • The service will open application B and take a screenshot.
  • Upon completion of the service, the service will close appB.
  • Then it will extract the image and upload it to the server.
  • After a successful download, the service will stop and update the AlarmManager.

The same thing is repeated every day.

Not sure if this will work or not, but you can try

hope this helps. :)

+1
Dec 21 '16 at 7:54
source share



All Articles