我写了一个方法在所有版本的android中安装apk,它的工作原理直到android 8.但似乎android 8不响应这种方法
install_apk(File file) {
try {
if (file.exists()) {
String[] fileNameArray = file.getName().split(Pattern.quote("."));
if (fileNameArray[fileNameArray.length - 1].equals("apk")) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri downloaded_apk = getFileUri(context, file);
Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(downloaded_apk,
"application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(intent);
} else {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
这个方法用于获取api> = 23的uri
Uri getFileUri(Context context, File file) {
return FileProvider.getUriForFile(context,
context.getApplicationContext().getPackageName() + ".HelperClasses.GenericFileProvider"
, file);
}
Run Code Online (Sandbox Code Playgroud) 我想将本地图像文件加载到CoilJetpack Compose 中 Image,但搜索仅生成使用 Web url 或传递转换为bitmaps 的文件的方法。
可以Coil 将本地图像文件直接加载到 Compose 中Image吗?
我想使用CircularProgressIndicator材质库中的宽度自定义尺寸,但是当我为视图设置任何宽度或高度时,只是视图本身发生变化而不是其中的圆圈。我想要实现的是填充图像视图的进度,如下图所示
这是我的代码
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/circleBackground"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="H,1:1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.5"
app:shapeAppearanceOverlay="@style/circleImageView"
tools:src="@tools:sample/avatars" />
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progressBar"
android:layout_width="0dp"
android:layout_height="0dp"
android:max="100"
android:progress="50"
app:indicatorColor="@color/green_true"
app:indicatorDirectionCircular="clockwise"
app:layout_constraintBottom_toBottomOf="@id/circleBackground"
app:layout_constraintLeft_toLeftOf="@id/circleBackground"
app:layout_constraintRight_toRightOf="@id/circleBackground"
app:layout_constraintTop_toTopOf="@id/circleBackground"
app:trackColor="#50ffffff"
app:trackCornerRadius="90dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) 我正在将我的项目从视图系统转换为撰写。在旧视图系统中的应用程序页面之一中,我有一个带有一个 viewPager 的片段,它只是使同一片段的一些页面具有不同的数据来显示。虽然每个片段都有自己的生命周期,但每个片段可以有多个独立的 viewModel。据我所知,在 Compose 中,viewModel 生命周期附加到导航图,因此每次我尝试访问 viewModel 时,它只会返回在第一次调用中创建的相同 viewModel 对象。如何在撰写中实现相同的视图系统行为?
这是我的应用程序现在正在执行的操作的简化版本
@Composable
fun MainScreen(mainViewModel: MainViewModel = hiltViewModel()) {
val pages = mainViewModel.pages.collectAsState()
val pagerState = rememberPagerState(pageCount = pages.size)
HorizontalPager(state = pagerState) {
ChildScreen()
}
}
@Composable
fun ChildScreen(childViewModel:ChildViewModel = hiltViewModel()){
}
Run Code Online (Sandbox Code Playgroud)
这里childViewModel始终是所有页面的一个对象
我收到了Google Play控制台发出的警告,该警告引导我访问此页面,因为我在我的应用中使用了JavaScript界面并建议了两个选项来解决问题.
选项1告诉:
确保没有任何对象添加到任何加载不受信任的Web内容的WebView的JavaScript接口.您可以通过两种方式执行此操作:
通过调用addJavascriptInterface确保没有任何对象添加到JavaScript接口.
在WebView加载不受信任的内容之前,通过removeJavascriptInterface从shouldInterceptRequest中的JavaScript接口中删除对象.
但是我无法理解google究竟特意说的是:
在WebView加载不受信任的内容之前,通过removeJavascriptInterface从shouldInterceptRequest中的JavaScript接口中删除对象
谁能告诉我更多解释?
将 AndroidStudio 更新为后,4.2我无法在可调试进程中看到我的应用程序。更新之前一切都很好。我尝试过但没有改变的是:
- 重新启动手机
- 重新启动android studio
- 重新启动电脑
- 使缓存无效
- 重建并清理
- 删除构建文件夹
- 禁用手机中的开发人员选项
- 尝试模拟器
我有一个带有 GridLayoutManager 作为布局管理器的 recyclerview,我想要实现的效果如下图所示
正如您所看到的,每行可能有多个项目,仅基于项目宽度,每个项目都是一个具有wrap_content宽度的 TextView,但所有项目都具有相同的高度。
我知道可以设置行跨度,SpanSizeLookup但为此,我应该知道之前的跨度计数,而我的列表行将仅按项目宽度填充
有人可以帮助我吗?
我使用 Hilt 进行 DI,最近(经过一些更新)android studio 警告我关于注释有@ApplicationContext内存泄漏的上下文文件。据我所知,我知道应用程序上下文在应用程序运行时可用,并且它不应该导致内存泄漏,但似乎 lint 的想法不同。是我错了还是这只是一个错误?