随着 Android Q 的新隐私更改生效,现在任何使用MediaProjectionapi 的应用程序都必须在清单下的服务标签中指定android:foregroundServiceType属性。
但最近,我注意到虽然我设置了,android:foregroundServiceType="mediaprojection"但还是抛出了一个安全异常。有人知道我做错了什么吗?
显现:
<service
android:name=".services.MediaProjectionService"
android:enabled="true"
android:exported="false"
android:foregroundServiceType="mediaProjection" />
Run Code Online (Sandbox Code Playgroud)
抛出异常:
java.lang.RuntimeException: Unable to start service com.package.app.services.MediaProjectionService@6d0fed2 with Intent { act=com.package.app.services.action.startrecording cmp=com.package.app/.services.MediaProjectionService(has extras) }: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4103)
at android.app.ActivityThread.access$1800(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7343)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933)
Caused by: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION
at android.os.Parcel.createException(Parcel.java:2071)
at android.os.Parcel.readException(Parcel.java:2039)
at android.os.Parcel.readException(Parcel.java:1987) …Run Code Online (Sandbox Code Playgroud) 假设我的应用程序是"A",我使用应用程序"A"中的自定义意图启动应用程序"B"的活动.它可以正常工作,因为我想要它.我使用的代码是app"B"的清单:
<activity
android:name=".mysecondAct"
android:label="@string/title_activity_second" >
<intent-filter>
<action android:name="com.example.intent.action.Dream" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
在应用程序"A"的活动中,我启动应用程序"B",
Intent i =new Intent("com.example.intent.action.Dream");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
现在,如何指定应将意图发送到的特定包,以便只有该应用程序接收意图并启动活动?原因是,我有一个包列表,用户选择要调用哪一个.
我正在尝试构建 Android 应用程序,然后通过以下方式将工件上传到另一个服务器:
到目前为止,我有 2 个阶段build和deploy。因此,一旦构建成功并且工件上传,部署作业就会启动,它应该能够传入build工件的作业 ID(工件名称是全局变量),最终将卷曲我的 php 页面以启动下载。这是我的 gitlab ci 配置:
stages:
- buildRelease
- deploy
variables:
fileName: artifact-Name.apk
buildReleaseApp:
variables:
GIT_SUBMODULE_STRATEGY: recursive
before_script:
- chmod +x ./gradlew
- echo $setUpBuildScript | base64 -d > buildRelease.sh
- chmod +x prepareConfig.sh
stage: buildRelease
script:
- sh buildRelease.sh
only:
- tags
artifacts:
paths:
- app/build/outputs/apk/playstore/release/*.apk
after_script:
- mv app/build/outputs/apk/playstore/release/*.apk app/build/outputs/apk/playstore/release/${fileName}
deployReleaseApp:
variables:
dependencies: …Run Code Online (Sandbox Code Playgroud) 我正在尝试将图像设置为可折叠工具栏,该工具栏显示在> 23api的半透明状态栏后面.但即使在styles.xml中将状态栏设置为透明并在活动的清单中应用主题并在imageview和collapsingToolbar的布局中设置fitSystemWindows,图像也不适用于状态栏.xml和截图如何:
Layout.xml
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:fitsSystemWindows="false"
android:layout_height="match_parent" >
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="250dp" >
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
android:id="@+id/movie_banner"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe5e5e5"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/movies_details_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
style="@style/FabStyle"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
styles.xml
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:textColorPrimary">@android:color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是它在我的手机上的样子.
--------------------更新--------------------雅克森的答案部分解决了.现在,当工具栏向上滚动时,图像被设置为状态栏,但是一旦完全向上,我看到如下图所示.请注意,操作栏也有所提升.我需要实现这样的目标:图像设置在状态栏上

xml android android-coordinatorlayout android-collapsingtoolbarlayout