Ich versuche eine kleine Android-App zu erstellen, die eine Screenshot-Erfassung des aktuellen Bildschirms auslöst, wenn eine bestimmte Benachrichtigung erscheint. Zum Beispiel, ich bin auf WhatsApp und eine WhatsApp Benachrichtigung erscheint -> Das löst eine WhatsApp Capture.Screenshot des aktuellen Bildschirms erstellen, NICHT die aktuelle Aktivität
Nun, mein aktueller Code erkennt tatsächlich Benachrichtigungen und löst einen Screenshot aus, wenn eine Benachrichtigung kommt, aber nicht so, wie ich es möchte. Ich erhalte einen Screenshot meiner MainActivity, auch wenn sie nicht auf dem Bildschirm angezeigt wird. Ich möchte nur screenshot, was es auf dem Bildschirm erscheint. Es scheint einfach, aber ich kann es nicht tun!
ich meine aktuelle NotificationReceiver Klasse verlassen, die fehlschlägt, weil es die MainActivity und den Bildschirm nicht erfasst:
class NotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String temp = intent.getStringExtra("notification_event") + "\n" + txtView.getText();
txtView.setText(temp);
if (intent.getStringExtra("notification_event").contains("bet")) {
Log.i("Dentro", "dentro");
Date now = new Date();
android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);
try {
// image naming and path to include sd card appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";
// create bitmap screen capture
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
File imageFile = new File(mPath);
FileOutputStream outputStream = new FileOutputStream(imageFile);
int quality = 100;
bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
outputStream.flush();
outputStream.close();
} catch (Throwable e) {
// Several error may come out with file handling or OOM
Log.i("Catch","Error dentro del if(contains)");
e.printStackTrace();
}
}//fin if
}
}
Irgendwelche Ideen, wie ich vorgehen kann? Ich bin eigentlich festgefahren. Hilfe würde wirklich geschätzt werden!