Now I'm trying to run
HardwarePropertiesManager hardwarePropertiesManager = getApplicationContext().getSystemService(HardwarePropertiesManager.class);
hardwarePropertiesManager.getDeviceTemperatures(HardwarePropertiesManager.DEVICE_TEMPERATURE_CPU, HardwarePropertiesManager.TEMPERATURE_CURRENT);
to check cpu usage and temperature..
but, the exception occurred, which is
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.___/com.example.___.MainActivity}:
java.lang.SecurityException: The caller is neither a device
owner, nor holding the DEVICE_POWER permission, nor the current
VrListener.
is there any method to check cpu temperature and cpu usage(memory, core)??
As the documentation mentions HardwarePropertiesManager is available for applications which are device owners - https://developer.android.com/reference/android/os/HardwarePropertiesManager
You can try reading the data from file
sys/class/hwmon/hwmonX/temp1_input
There are some changes based on vendors. You can refer to https://stackoverflow.com/a/59306562 for comprehensive list.
Related
We developing app for food ordering. In this case we implemented Braintree payment. All is well. The next step is to implement Google Pay (I pay your attention, NOT Android Pay).
I used this documentation:
Braintree Docs:
https://developers.braintreepayments.com/guides/pay-with-google/configuration/android/v2
Google PwG Docs:
https://developers.google.com/payments/setup
This how do we implemented Google Pay:
private GooglePaymentRequest getGooglePaymentRequest(String total) {
return new GooglePaymentRequest()
.transactionInfo(TransactionInfo.newBuilder()
.setTotalPrice(total)
.setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL)
.setCurrencyCode("AUD")
.build())
.emailRequired(false)
.shippingAddressRequired(false)
.phoneNumberRequired(false)
.allowPrepaidCards(true)
.billingAddressRequired(false);
}
And use:
String total = String.format(Locale.getDefault(), "%1$.2f", basket.total);
DropInRequest dropInRequest = new DropInRequest()
.clientToken(clientToken)
.amount(total)
.googlePaymentRequest(getGooglePaymentRequest(total))
.collectDeviceData(true);
getMvpView().showBraintreePaymentScreen(dropInRequest);
In this case we got two situations:
On my colleague's device all is working well (video: https://drive.google.com/open?id=1wEXbv8qzGXzuXWDUy7-bhIdud_4H_s2V)
On my side I got crash (video: https://drive.google.com/open?id=15gvtkNGZ9w6v1ym7cDkwWCnqHh5JUvL7)
After this I started debug and observed next situation:
As you see in Braintree's BaseActivity I got exception with statusCode=10 that means DEVELOPER_ERROR.
So is anyone have thoughs how it can be fixed?
I ran into the same error implementing Google Pay and I found the answer to my problem here:
https://developers.google.com/pay/api/android/support/troubleshooting
Quote:
The most common error message is ERROR_CODE_DEVELOPER_ERROR. This error message also appears in the UI as a dialog with the following text:
Request Failed
An unexpected error has occurred. Please try again later.
To learn more about this error, follow these steps:
Make sure ADB is installed on your computer.
Make sure USB debugging is enabled on your device.
Connect your phone to the computer using a USB cable.
Run the following command in a terminal or command prompt on your computer:
adb -d logcat -s WalletMerchantError
The response indicates the underlying reason for the error. For example, you may see:
02-26 17:41:28.133 14593 14593 W WalletMerchantError: Error in
loadPaymentData: This merchant profile does not have access to this
feature.
Note: The error only becomes visible in logcat after you've pressed OK to close the alert.
The action you need to take to resolve the issue depends on the error message.
What is the proper way to get the serial number from native on Android O without calling the Java Build.getSerial().
On Android < 26 versions from native we could get the device serial number using the following code:
string serial = read_property("ro.boot.serialno");
...
string read_property(const string& property_name) {
char propertyValue[PROP_VALUE_MAX];
int propertyLen = __system_property_get(property_name.c_str(), propertyValue);
...
}
On Android O this throws an error:
Access denied finding property "ro.boot.serialno"
Although the READ_PHONE_STATE permission is granted. Seems to be related to the deprecated Build.SERIAL in Android 26.
I managed to get this property using adb, so the value is not removed and is there:
adb shell getprop ro.boot.serialno
You can use Build.getSerial() to get the serial number.
If the user has granted the READ_PHONE_STATE permission then there is no problem but if the user revoked the permission or has never granted it - you should take into consideration that you will get a SecurityException at runtime when trying to retrieve it.
In general - it looks like Google is slowly pushing to prevent apps from using personal identifiable information (like serial numbers of device) over the last few years so and you should look into alternatives like installationId.
Working on a basic map using UnfoldingMaps Library and Eclipse. It's for educational purposes(taking a course for OOP Java), and when trying to access the google map provider using map object:
AbstractMapProvider provider = new Google.GoogleProvider();
use then the draw() method to create the map.I run the applet(on eclipse) and it runs for the first time. But after I ran it the second time, it starts giving me the following error:
Unfolding Map v0.9.7 (UCSD edition)
Using OpenGLMapDisplay with processing.opengl.PGraphics2D
java.io.IOException: Server returned HTTP response code: 403 for URL: http://mt1.google.com/vt/lyrs=m#116&hl=de&x=180&y=414&z=10&s=Galileo
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1876)
at sun.net.www.protocol.http.HttpURLConnection.access$200(HttpURLConnection.java:91)
at sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1466)
at sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1464)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:782)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1463)
at java.net.URL.openStream(URL.java:1045)
at processing.core.PApplet.createInputRaw(PApplet.java:7267)
at processing.core.PApplet.createInput(PApplet.java:7235)
at processing.core.PApplet.loadBytes(PApplet.java:7462)
at processing.core.PApplet.loadImage(PApplet.java:5879)
at de.fhpotsdam.unfolding.tiles.TileLoader.getTileFromUrl(Unknown Source)
at de.fhpotsdam.unfolding.tiles.TileLoader.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
The file "http://mt1.google.com/vt/lyrs=m#116&hl=de&x=180&y=414&z=10&s=Galileo" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
Possible causes I read online:
1.6 java compiler security concerns
trying to access tiles abuses terms of service with google API(really not super aware of the terms and since it's my first map, not sure the tiles how they are accessed)
multiple requests over the limit(not possible in my case as the second time I run the applet, it starts giving me the error)
I'm just trying to find a way if possible to use the google map provider for my project. I would not like to use other providers(such as Microsoft)as google's in my perspective is more complete.
Any help is much appreciated.
Maybe you are using more than one object to provide the map in your code, example:
AbstractMapProvider provider1 = new Google.GoogleTerrainProvider();
AbstractMapProvider provider2 = new Google.GoogleTerrainProvider();
Instead, use just one object provider in your whole code, and then reset your device ip address, or restart your router, because google won't allow the ip address to use the provider even after fixing your code due to the abuse of the service terms.
that will fix the problems.
You may have exceeded the number of allowed queries to Google for the day. You can use use an alternative map(http://unfoldingmaps.org/javadoc/de/fhpotsdam/unfolding/providers/package-summary.html) provider or work offline if this happens.You have reported that you will only be blocked for 24 hours from google so you can restore using the provider at that time.
Can someone help me with name of api which enables realtime prediction of a model. Please note that i am not requesting for RealtimeEndpointRequest object. i have gone through the entire documentation of AWS Machine Learning SDK but haven't found any thing.
Edit 1 :
This is the code that i have used -
CreateRealTimePrediction createRealTimePrediction ;
CreateRealtimeEndpointRequest createRealtimeEndPointReq;
CreateRealtimeEndpointResult createRealtimeEndPointRes;
PredictRequest predReq;
String mlModelId="ml-Lkqmcs8cM2W";
createRealtimeEndPointReq.setMLModelId(mlModelId);
PredictResult predRes = null;
Map<String,String> record=null;
// assume i have set a record in the Map.
createRealtimeEndPointRes = amlClient.createRealtimeEndpoint(createRealtimeEndPointReq);
String predictEndpoint=createRealtimeEndPointRes.getRealtimeEndpointInfo().getEndpointUrl();
predReq= new PredictRequest();
predReq.setMLModelId(mlModelId);
for (int i=0;i<recordKeys.length;i++){
record.put(recordKeys[i],recordValues[i]);
}
predReq.setRecord(record);
predReq.setPredictEndpoint(predictEndpoint);
predRes=amlClient.predict(predReq);
return predRes;
}
Now what is happening is - if i enable the real time prediction by using aws management console manually and then run this segment of code, then the results are generated as expected but when i the realtime prediction is disabled, then i get this error -
Exception in thread "main" com.amazonaws.services.machinelearning.model.PredictorNotMountedException: Either ML Model with id ml-Lkqmcs8
cM2W is not enabled for real-time predictions or the MLModelId is invalid. (Service: AmazonMachineLearning; Status Code: 400; Error Code
: PredictorNotMountedException; Request ID: 2dc70e58-07d0-11e5-a0c7-bb93f17d1b2e)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1160)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:748)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:467)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:302)
at com.amazonaws.services.machinelearning.AmazonMachineLearningClient.invoke(AmazonMachineLearningClient.java:1995)
at com.amazonaws.services.machinelearning.AmazonMachineLearningClient.predict(AmazonMachineLearningClient.java:637)
at com.nrift.aml.prediction.realtime.CreateRealTimePrediction.createRealTimePrediction(CreateRealTimePrediction.java:61)
at RealTimePrediction.main(RealTimePrediction.java:53)
which effectively means that this segment of code is not enabling the real time prediction though i have used
CreateRealtimeEndpoint
api in it.
P.s- the code segment i have posted is a not complete, the complete code is working correctly so you can make assumptions about the correctness of code.
The API you are looking for is CreateRealtimeEndpoint. Creating a real-time endpoint is the mechanism for enabling the model to be used for real-time predictions. When you no longer need to use this model, you can destroy the endpoint with the DeleteRealtimeEndpoint API. The model always stays intact, so you can create/delete endpoints when needed.
I'm trying to start a Amazon EC2 cloud machine with [startInstance][2] method using aws-sdk in Java. My code is as follows.
public String startInstance(String instanceId) throws Exception {
List<String> instanceIds = new ArrayList<String>();
instanceIds.add(instanceId);
StartInstancesRequest startRequest = new StartInstancesRequest(
instanceIds);
startRequest.setRequestCredentials(getCredentials());
StartInstancesResult startResult = ec2.startInstances(startRequest);
List<InstanceStateChange> stateChangeList = startResult
.getStartingInstances();
log.trace("Starting instance '{}':", instanceId);
// Wait for the instance to be started
return waitForTransitionCompletion(stateChangeList, "running",
instanceId);
}
When I run the above code, i'm getting the following AWS error:
Status Code: 400, AWS Request ID: e1bd4795-a609-44d1-9e80-43611e80006b, AWS Erro
r Code: InvalidInstanceID.NotFound, AWS Error Message: The instance ID 'i-2b97ac
2f' does not exist
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpCli
ent.java:538)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.ja
va:283)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:168
)
at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.jav
a:5208)
at com.amazonaws.services.ec2.AmazonEC2Client.startInstances(AmazonEC2Cl
ient.java:2426)
AWS Error Message: The instance ID 'i-2b97ac2f' does not exist
You'll have to take the AWS response for granted here, i.e. the instance does not exist ;)
But seriously: Presumably you have already verified that you are actually running an instance with this ID in your account? Then this is most likely caused by targeting the wrong API endpoint, insofar an instance ID is only valid within a specific region (if not specified, the region defaults to 'us-east-1', see below).
In this case you need to specify the actual instance region via the setEndpoint() method of the AmazonEC2Client object within the apparently global ec2 variable before calling startInstances().
There are some examples regarding Using Regions with the AWS SDKs and all currently available AWS regional endpoint URLs are listed in Regions and Endpoints, specifically the Amazon Elastic Compute Cloud (EC2) defaults to 'us-east-1':
If you just specify the general endpoint (ec2.amazonaws.com), Amazon
EC2 directs your request to the us-east-1 endpoint.
We run a service (Qubole) that frequently spawns and then tags (and in some cases terminates) AWS instances immediately.
We have found that Amazon will, every once in a while, claim an instanceid as invalid - even though it has just created it. Retrying a few times with some sleep time thrown in usually solves the problem. Even a total retry interval of 15s proved insufficient in rare cases.
This experience comes from the useast region. We do not make api calls to different regions - so that is not an explanation. More likely - this is the infamous eventual consistency at work - where AWS is unable to provide read-after-write consistency for these api calls.
I am using the AWS ruby api and I noticed the same issue when creating an AMI image and its status is pending when I look in the AWS console but after a while the image is available for use.
Here is my script
image = ec2.images.create(:name => image_name, :instance_id => ami_id, :description => desc)
sleep 5 while image.state != :available
I sleep for about 5 sec for image to be in available but I get the error saying that the "AWS Error Message: InvalidInstanceID.NotFound". During my testing this is fine but most of the time this seems to be failing during continuous integration builds.
InvalidInstanceID.NotFound means the specified instance does not exist.
Ensure that you have indicated the region in which the instance is located, if it's not in the default region.
This error may occur because the ID of a recently created instance has not propagated through the system. For more information, see Eventual Consistency.