Playback starts YouTube’s embedded player (privacy-enhanced mode).
How to take screenshot from your Android App and open the image file programmatically?
ChannelProgrammer WorldDescription from the creator
This video shows the steps to take screenshots of the phone's screen area and save it as an image file at the desired file path. For image file it considers current data and time as unique name of the file. Further it shows how you can open the captured image file which can be shared over email, whatsapp, drive or bluetooth. All these steps are done programmatically and hence these APIs can be used to automate the task or control the screenshot remotely via SMS or some notifications.
We hope you like this video. For any query, suggestions or appreciations we will be glad to hear from you at: [email protected] or visit us at: programmerworld.co
programmerworld.co/android/how-to-take-screensh…
Source Code:
package com.example.myscreenshotshotapp;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Calendar;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this,new String[]{WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
}
public void ScreenshotButton(View view){
View view1 = getWindow().getDecorView().getRootView();
view1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view1.getDrawingCache());
view1.setDrawingCacheEnabled(false);
String filePath = Environment.getExternalStorageDirectory()+"/Download/"+ Calendar.getInstance().getTime().toString()+".jpg";
File fileScreenshot = new File(filePath);
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(fileScreenshot);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(fileScreenshot);
intent.setDataAndType(uri,"image/jpeg");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
}
We hope you like this video. For any query, suggestions or appreciations we will be glad to hear from you at: [email protected] or visit us at: programmerworld.co
programmerworld.co/android/how-to-take-screensh…
Source Code:
package com.example.myscreenshotshotapp;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Calendar;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this,new String[]{WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
}
public void ScreenshotButton(View view){
View view1 = getWindow().getDecorView().getRootView();
view1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(view1.getDrawingCache());
view1.setDrawingCacheEnabled(false);
String filePath = Environment.getExternalStorageDirectory()+"/Download/"+ Calendar.getInstance().getTime().toString()+".jpg";
File fileScreenshot = new File(filePath);
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(fileScreenshot);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(fileScreenshot);
intent.setDataAndType(uri,"image/jpeg");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
}
About this tutorial
Programmer World published this 19:14 video tutorial on December 1, 2019. It has been watched 11,427 times on YouTube.
- Channel
- Programmer World
- Category
- Education
- Duration
- 19:14
- Published
- December 1, 2019
- Views
- 11,427
- Likes
- 98
Tags
Share
This tutorial in other languages
- FRComment prendre capture d'écran de votre application Android et ouvrez le fichier image programme?
- ESCómo tomar captura de pantalla de la aplicación de Android y abrir el archivo de imagen mediante programación?
- PTComo tirar screenshot de sua App Android e abra o arquivo de imagem por meio de programação?
- ITCome prendere screenshot dal proprio App Android e aprire il file di immagine di programmazione?
- DEWie Screenshot von Ihrem Android-App und öffnen Sie die Bilddatei programmatisch nehmen?
- NLHoe te screenshot te nemen van je Android-app en open het beeld programmatisch?
- RUКак взять скриншот с вашего Android App и откройте файл изображения программно?
- PLJak wziąć zrzut ekranu z aplikacji na Androida i otworzyć plik obrazu programowo?
- JAあなたのAndroidアプリからスクリーンショットを撮ると、プログラム、画像ファイルを開く方法?
- ARكيفية اتخاذ قطة من الروبوت الخاص بك التطبيقات وفتح ملف الصورة برمجيا؟
- HIकैसे अपने Android App से स्क्रीनशॉट लेने और प्रोग्राम के रूप में छवि फ़ाइल को खोलने के लिए?
- IDBagaimana untuk mengambil screenshot dari App Android Anda dan buka file gambar pemrograman?