我正在使用Android下载管理器下载文件列表.最近我遇到了一份崩溃报告说
Unknown java.lang.IllegalArgumentException: Unknown URL content://downloads/my_downloads
然后,我想通了,原因是因为用户禁用了Android下载管理器.我通过使用以下代码检查下载管理器的包名来检查是否已禁用下载管理器.
int state = this.getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads");
Run Code Online (Sandbox Code Playgroud)
现在,我需要找到一种方法来启用下载管理器,如果它被禁用.我尝试使用Manifest中的权限设置它的启用状态但我一直得到安全异常.
this.getPackageManager().setApplicationEnabledSetting("com.android.providers.downloads", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>
Run Code Online (Sandbox Code Playgroud)
所以我认为它可能无法访问,因为它是一个系统应用程序.(谷歌Play应用程序).
有没有办法将用户重定向到下载管理器应用程序信息视图?让用户启用它?如果无法以编程方式在运行时启用它.
android android-package-managers android-download-manager android-settings
我正在研究新的权限模型(Android 6.0 Marshmallow),我想知道有没有办法以编程方式打开应用程序的权限窗口?
不仅是申请细节
我设法用这样的东西打开第二个屏幕
private void goToSettings() {
Intent myAppSettings = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + getPackageName()));
myAppSettings.addCategory(Intent.CATEGORY_DEFAULT);
myAppSettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(myAppSettings);
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何打开第一个.
非常感谢您的帮助:)
permissions android android-settings android-6.0-marshmallow
为什么我这样问:(也是在应用程序中尝试它的原因)
当我们在Lollipop中使用Google地图时会发生这种情况.即使位置已禁用,也会在用户从地图应用输入后以高精度模式打开,而无需访问"设置".
可以实现类似的功能以启用蓝牙,其中操作在我的应用程序中启动; 用户需要做出选择,但用户不会重定向到"设置",使用:
startActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE));
哪个可以在BluetoothAdapter上找到,现在我们知道没有LocationAdapter,所以我环顾了gms-> LocationServices,基本上几乎所有的位置API引用,android.location.LocationManager,但似乎没有任何像ACTION_REQUEST_ENABLE现在可用.
希望有相同的其他方法,更多人尝试过.
请注意:
context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));不起作用.
android android-location google-play-services android-settings android-5.0-lollipop
用户可以在"数据使用"屏幕上定义移动数据使用的限制和/或警告限制.那么如何通过代码获取此信息呢?
本机操作系统的数据使用配置屏幕.

我想要极限值和警告值.
我已经尝试过但不能正常工作并且总是向两者返回NULL:
final Long recommendedBytes = DownloadManager.getRecommendedMaxBytesOverMobile( this.context );
final Long maximumBytes = DownloadManager.getMaxBytesOverMobile( this.context );
// recommendedBytes and maximumBytes are NULL
Run Code Online (Sandbox Code Playgroud)
而TrafficStats类只是传输数据而不是限制.
android network-traffic user-preferences android-download-manager android-settings
我已经正确设置了pref_general,它的值以及运行intent的代码:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Intent intecao = new Intent(characterList.this, SettingsActivity.class);
startActivity(intecao);
return true;
}
return super.onOptionsItemSelected(item);
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我点击选项弹出窗口中的设置,它将在我的手机/ 7"平板电脑中正确打开,但对于更大的平板电脑,如9"或更多,它会给我一个空白的屏幕弹出窗口,而不会写任何内容,例如如下:

我该如何解决这个问题?导致这种情况发生的问题是什么?
---编辑---
这是我的pref_general:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Made by Megafuji and Kintups"/>
<ListPreference
android:key="console1"
android:title="Console"
android:summary="Select your console" …Run Code Online (Sandbox Code Playgroud) 我看到了一个我最好的问题是否有一个独特的Android设备ID?
我使用了一些以下代码来获取唯一ID.
public static String getDeviceId(Activity context) {
PermissionsChecker checker = new PermissionsChecker(context);
if (checker.lacksPermissions(Manifest.permission.READ_PHONE_STATE))
PermissionsActivity.startActivityForResult(context, 0, REQUIRED_PERMISSION);
else {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String tmDevice = tm.getDeviceId();
final String androidId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32));
return deviceUuid.toString();
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
但是我在悬停时会收到一些警告
tm.getDeviceId();
和
Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
如下:
建议不要使用getString来获取设备标识符.
除高价值防欺诈和高级电话用例外,不建议使用设备标识符.对于广告用例,请使用AdvertisingIdClient $ Info#getId并使用InstanceId#getId进行分析.
有什么解决方案吗?它有害还是其他什么?
android telephonymanager android-identifiers android-settings
在基于GPS的应用中,重要的是用户启用他的GPS.如果没有,那么通常我们会显示一个对话框,说明用户" 应该从设置启用他的GPS以便能够使用此功能 ".
当用户按下OK时,他将被重定向到Settings页面,我不喜欢这个解决方案,因为它将用户从应用程序上下文中带到了设置中.
我注意到"谷歌地图"应用程序有一个更好的解决方案,即在需要GPS功能时显示一个整洁的对话框.一旦用户选择"OK" GPS将被启用直接没有任何转向的设置.
我可以在不将用户重定向到设置屏幕的情况下启用GPS,就像在"谷歌地图"应用程序中一样吗?
看看下面的图片:

我使用它是Settings.ACTION_APPLICATION_DETAILS_SETTINGS为了在用户未故意授予权限时发出请求。
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getActivity().getPackageName(), null);
intent.setData(uri);
getActivity().startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
该代码仅在 Android 13 下运行良好。如果我在 Android 13 中运行此代码,则会发生异常。
"Bad call made by uid 1000. Package "package name" does not belong to uid -1.
noteOperation
java.lang.SecurityException: Specified package "package name" under uid -1 but it is not
at com.android.server.appop.AppOpsService.verifyAndGetBypass(AppOpsService.java:4858)
at com.android.server.appop.AppOpsService.noteOperationUnchecked(AppOpsService.java:3586)
at com.android.server.appop.AppOpsService.noteOperationImpl(AppOpsService.java:3574)
at com.android.server.appop.AppOpsService.-$$Nest$mnoteOperationImpl(Unknown Source:0)
at com.android.server.appop.AppOpsService$CheckOpsDelegateDispatcher.lambda$noteOperation$4(AppOpsService.java:7928)
at com.android.server.appop.AppOpsService$CheckOpsDelegateDispatcher.$r8$lambda$oOwUoG55BBmJ6yiwhp3OAq3tQ30(Unknown Source:0)
at com.android.server.appop.AppOpsService$CheckOpsDelegateDispatcher$$ExternalSyntheticLambda4.apply(Unknown Source:32)
at com.android.server.policy.AppOpsPolicy.noteOperation(AppOpsPolicy.java:225)
at com.android.server.appop.AppOpsService$CheckOpsDelegateDispatcher.noteOperation(AppOpsService.java:7926)
at com.android.server.appop.AppOpsService.noteOperation(AppOpsService.java:3558)
at com.android.internal.app.IAppOpsService$Stub.onTransact(IAppOpsService.java:486)
at android.os.Binder.execTransactInternal(Binder.java:1316)
at …Run Code Online (Sandbox Code Playgroud)