我的应用程序使用BatteryManager.BATTERY_PROPERTY_CURRENT_NOW来获取设备的电池电流:
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
int current = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW), context);
Run Code Online (Sandbox Code Playgroud)
但是,它不适用于例如Samsung Galaxy TabA。它仅返回0。
其他应用程序甚至在该设备上显示当前电流。他们是怎么做到的呢?我的方法有哪些替代方法?
我想在使用 DownloadManager 单击按钮时更新应用程序的 sqlite 数据库。
但它说“java.lang.IllegalArgumentException:不是文件URI:/data/user/0/com.example.laudien.listviewtesting/databases/Employees”
我做错了什么?我需要许可吗?互联网权限已在清单中。
这是我的 updateDb() 方法的代码:
private void updateDb() {
DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); // create download manager
DownloadFinishedReceiver receiver = new DownloadFinishedReceiver(); // create broadcast receiver
registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); // register the receiver
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(DATABASE_URL)); // create a download request
// delete database file if it exists
File databaseFile = new File(getDatabasePath(DATABASE_NAME).getAbsolutePath());
if(databaseFile.exists())
databaseFile.delete();
request//.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN) // not visible
.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI) // only via wifi
.setDestinationUri(Uri.parse("file:" + getDatabasePath(DATABASE_NAME).getAbsolutePath())); // set path in app …Run Code Online (Sandbox Code Playgroud) 我写了一个像这里描述的预定函数:https : //firebase.google.com/docs/functions/schedule-functions
我现在如何测试这个功能?当我包装这个函数时(就像我对任何其他云函数一样),有一个错误说:“属性 'wrap' 在类型 'TestFunction' 上不存在。”
const functionWrapper = test.wrap(function);
Run Code Online (Sandbox Code Playgroud)
有没有其他方法可以测试这些功能?