This is the 14th day of my participation in the August Text Challenge.More challenges in August
background
After the project was migrated to Android Q, it was found that all previous broadcasts could not be received, including boot broadcast and custom broadcast, etc. Error :Background Execution not allowed: receiving Intent { act=izis_MinaPushServiceOpen_kyteach flg=0x10 (has extras) } to cn.izis.kyteach/.receiver.DataReceiverPublic
After Android 8.0, we learned that all broadcasts require dynamic registration, that is, static broadcasts in the manifest file do not work.
code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
registerReceiver();
}
public void registerReceiver(){
m_adbReceiver = new AdbBootBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.intent.action.BROADCAST_FORM_ADB");
registerReceiver(m_adbReceiver, intentFilter);
IntentFilter intentFilter2 = new IntentFilter();
m_bootReceiver = new BootBroadcastReceiver();
intentFilter2.addAction("android.intent.action.android.intent.action.BOOT_COMPLETED");
registerReceiver(m_bootReceiver, intentFilter2);
m_installReceiver = new InstallResultReceiver();
IntentFilter intentFilter3 = new IntentFilter();
intentFilter3.addAction("android.content.pm.extra.STATUS");
registerReceiver(m_installReceiver, intentFilter3);
@Override
protected void onDestroy() {
super.onDestroy();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
unregisterReceiver(m_adbReceiver);
unregisterReceiver(m_bootReceiver);
unregisterReceiver(m_installReceiver);
}
System.out.println("-- onDestroy()");
}
Copy the code
background
The screenshot method of the previous project was screencap -p command, which called the Android CMD function in QT to achieve the screenshot. However, the defect of this method was slow, and the screenshot sometimes required 5S. Actually, in QT, we have a better way to take screenshots.
Plan to introduce
In QT5.12, we tried the grabWindow method of QScreen and the Grab method of QWidget. Neither approach works perfectly on Android. For a number of reasons, we upgraded the QT version to QT5.15 because of concernsscreencap -p
The efficiency of the method is relatively low, in order to optimize, we tryQPixmap grabWidget
Method, found that this function can achieve perfect screenshots, although in the official QT documentation it says:
QWidget:: Grab () and QScreen::grabWindow() are not screenshots on Android.
code
m_bgpixmap = QPixmap::grabWidget(this, this->rect());
Copy the code