I have made an Android app that I am trying to port over to a blackberry 10 device. Currently, all of the functions of the app work except for one, where I try and get information about recent calls from the phone. This works fine on android, but does not seem to work on the blackberry 10 simulator I am using. Here is my code for the section:
final TextView time = (TextView) findViewById(R.id.AddNewEditTextTime);
final TextView date = (TextView) findViewById(R.id.AddNewEditTextDate);
final TextView number = (TextView) findViewById(R.id.AddNewEditTextNumber);
// fields to select.
String[] strFields = { android.provider.CallLog.Calls.NUMBER,
android.provider.CallLog.Calls.TYPE,
android.provider.CallLog.Calls.CACHED_NAME,
android.provider.CallLog.Calls.CACHED_NUMBER_TYPE,
android.provider.CallLog.Calls.DATE};
// only incoming.
String strSelection = android.provider.CallLog.Calls.TYPE + " = "
+ android.provider.CallLog.Calls.INCOMING_TYPE;
// most recent first
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
// get a cursor.
Cursor mCallCursor = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, // content provider
// URI
strFields, // project (fields to get)
strSelection, // selection
null, // selection args
strOrder // sortorder.
);
if (mCallCursor.moveToFirst()) {
String a = mCallCursor.getString(mCallCursor
.getColumnIndex("date"));
String b = mCallCursor.getString(mCallCursor
.getColumnIndex("number"));
mCallCursor.close();
SimpleDateFormat dateF = new SimpleDateFormat("dd-MMM-yyyy");
SimpleDateFormat timeF = new SimpleDateFormat("HH:mm");
String dateString = dateF.format(new Date(Long
.parseLong(a)));
String timeString = timeF.format(new Date(Long
.parseLong(a)));
time.setText(timeString);
date.setText(dateString);
number.setText(b);
}
The if(mCallCursor.moveToFirst()) statement is never entered on the blackberry 10 device, but works fine on Android. Is there something I'm missing / doing wrong, or is there no way to use the android.provider functions like this on a blackberry 10 device?
Apparently accessing call log is not yet supported
This is not supported, the Android API is not hooked up to retreive this data.
Edit: Usually when there's an equivalent native API, the corresponding API in Android will be supported. The Android API almost always uses the native equivalent for its implementation. AFAIK there isn't a native call logs API.
By bbenninger, at support forums.
Related
I have used geocoder to get the address through the location. However, the city name is in English and I want to show it in Arabic.
This is the code to get the address :
public String getAddress(double LATITUDE, double LONGITUDE) {
String city = "";
try {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if (addresses != null && addresses.size() > 0) {
String address = addresses.get(0).getAddressLine(0);
city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
}
} catch (IOException e) {
e.printStackTrace();
}
return city;
}
And then this is where I show the city name in a TextView :
String country_and_city = getAddress(latitude, longitude);
TextView city_name = findViewById(R.id.city);
city_name.setText(country_and_city);
Here, the city name will be displayed in English, how can I translate it or use other methods to show it in Arabic? For example, maybe using google-translate api or something if that is even possible
In order to use the Google Cloud Translation API, you need to have a project which has this API enabled, so you can make authenticated calls. You can set it up here.
Google provide a lot of sample codes, here, which you can use. The code below is used to translate a string Spanish(es) to German(de),
Translation translation =
translate.translate(
"Hola Mundo!",
Translate.TranslateOption.sourceLanguage("es"),
Translate.TranslateOption.targetLanguage("de"),
// Use "base" for standard edition, "nmt" for the premium model.
Translate.TranslateOption.model("nmt"));
System.out.printf("TranslatedText:\nText: %s\n", translation.getTranslatedText());
This article explains in details how to integrate the API within your Android Studio project, it can give you a better overview of the whole process.
Lastly, I should point out that according to the documentation,
Prices are pro rata (proportional and incremental). Charges are scaled to the number of characters actually provided to Cloud Translation. For example, if you send 575,000 characters for processing within a month, you are charged $1.50. The first 500,000 characters are free, and then you are charged for the additional 75,000 characters sent for detection, translation, or both.
As another alternative you can also check the googletrans library, which according to the documentation:
Googletrans is a free and unlimited python library that implemented Google Translate API. This uses the Google Translate Ajax API to make calls to such methods as detect and translate.
im making an android app which shows time of upload relative to the device time, but if the device time and date is not set correct then I do not get the desired result. so how to show warning or error if the device time and date is not correct or matches to the internet time. the app should not work unless the user set the date and time correct.
Get an extra UTC DateTimeOffset parameter as a response from the uploaded API & then convert it into your local timezone.
Cons -
If time is set wrong in the device, you have to create a localization method for it which can convert the timestamp to proper time without interfering with the local timezone.
You can use static timezoneid for conversion or get it by internal API calls, I uses Xamarin soo for me it's like -
var timeZoneId = "Asia/Calcutta"; // use it for worldwide application usage TimeZoneInfo.Local.ToString();
DateTime localizedDateTime = TimeZoneInfo.ConvertTimeFromUtc(incomingDATE.ToUniversalTime(), TimeZoneInfo.FindSystemTimeZoneById(timeZoneId));
Soo convert the received UTC DateTimeOffset to Localized time.
This thing works best for my apps. I use jsoup to search the google time and gets current time and then I compare the phone time with google time. So if these time are different you can stop user using a dialogbox or alertbox to tell them the times have changed. You can implement in MainActivity to check this condition.
Here is a snippet so you get the idea more clearly.
public class HomeActivity extends AppCompatActivity {
//phoneDate and phoneTime to get current phone date and time
String phoneDate = new SimpleDateFormat("dd MMM yyyy ").format(clnd.getTime()).trim();
String phoneTime = new SimpleDateFormat("hh:mm a").format(clnd.getTime()).trim();
String googleDate;
String googleTime ;
#Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.home);
Thread thread = new Thread(new Runnable() {
#Override
public void run() {
try {
//URL to search time
String url = "https://www.google.co.in/search?q=time";
Document document = Jsoup.connect(url).get();
org.jsoup.select.Elements time = document.getElementsByClass("gsrt vk_bk FzvWSb YwPhnf");
org.jsoup.select.Elements date = document.getElementsByClass("KfQeJ");
Log.d("HTML", "google date" + String.format(date.text()));
Log.d("HTML", "google time" + time.text());
googleDate = date.text().trim();
googleTime = time.text().trim();
//'0'is not present when hour is single digit
char second = googleTime.charAt(1);
if(second == ':'){
googleTime = "0" + googleTime;
}
Log.d("Proper format", "google time" + googleTime);
Log.d("Date", "your current url when webpage loading.." + phoneDate);
Log.d("Time", "your current url when webpage loading.." + phoneTime);
if(googleDate.contains(phoneDate) && googleTime.equals(phoneTime)){
Log.d("Time", "your current url when webpage loading.." + " true");
}else{
Log.d("Time", "your current url when webpage loading.." + " false");
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}
}
I'm kinda new to programming and got this as an assignment at work. I need to run a method that sends a message (FIX format) multiple times with multiple data sets. Here's how I build with its respective data and send the message:
private void testCaseAttempt(String testCaseName) throws Exception {
StringBuilder errorBuilder = new StringBuilder();
// Read test case arguments
new Arguments(testCaseName);
QuoteRequestBuilder builder = app.builders().quoteRequest();
BigDecimal b1;
b1 = new BigDecimal(10000);
//Date transactTime;
//transactTime = new Date(0);
//expireTime 10 minutes from now
Calendar now = Calendar.getInstance();
now.add(Calendar.MINUTE, 10);
Date expireTime = now.getTime();
//BUILD THE MESSAGE
builder
.setField(131, "5EB26EAAC074000D0000")
.symbol("DANBNK")
.securityID("SE0011116474")
.currency("SEK")
.securityIDSource("4")
.setField(54, "2")
.expireTime(expireTime)
.orderQty(b1)
.setField(64, "20200508")
.setField(1629, "10")
.setField(1916, "0")
.setField(60, "20200526-15:48:53.006")
.setField(761, "1")
.partyID("13585922", PartyIDSource.PROPRIETARY_CUSTOM_CODE, 11, null)
.partyID("1270", PartyIDSource.PROPRIETARY_CUSTOM_CODE, 13, null)
.partyID("SEB", PartyIDSource.PROPRIETARY_CUSTOM_CODE, 1, null)
.partyID("1786343", PartyIDSource.PROPRIETARY_CUSTOM_CODE, 117, null);
Message quoteRequestMessage = builder.getMessage();
//SEND THE MESSAGE
app.sendMessage(quoteRequestMessage, app.getSession(session));
long timeout = Properties.getLong(0L, "waitForMessage", "FIX");
Message responseMessage;
}
I build the FIX message with the "setfield" instructions then I just send it. This works just fine except I need to do it 20-30 times (so 20-30 messages) and I need to slightly change the values or parameteres each time.
I have an idea how to do this with cucumber using a feature file with an "Examples" table with my desired data so it calls this method but that feels like overkill at the moment. I was thinking of using an excel file with a table so I can comfortably change the values in each row and just feed it to this function somehow.
By the way, I didn't copy all the code in the function, I just copied the lines in which the msg is built and sent.
Any idea how I can do this? Your replies are much appreciated!
Thanks in advance.
Create your field map and just iterate that field map as below
Map<Integer,String> fieldMap = new HashMap<>();
fieldMap.put(131,"5EB26EAAC074000D0000");
fieldMap.put(54,"2");
fieldMap.put(64,"20200508");
fieldMap.put(1629,"10");
fieldMap.forEach((k,v)->{
builder.setField(k,v)
});
I am referring to documentation provided by azure at
https://learn.microsoft.com/en-us/azure/storage/common/storage-metrics-in-azure-monitor#read-metric-values-with-the-net-sdk
I have made changes and make the code work for java using azure-mgmt-monitor dependency. Here is the code
public void listStorageMetricDefinition() {
String resourceId = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}";
String subscriptionId = "*****************************";
String tenantId = "*****************************";
String applicationId = "*****************************";
String accessKey = "*****************************";
ApplicationTokenCredentials credentials = (ApplicationTokenCredentials) new ApplicationTokenCredentials(
applicationId, tenantId, accessKey, AzureEnvironment.AZURE).withDefaultSubscriptionId(subscriptionId);
MonitorManagementClientImpl clientImpl = new MonitorManagementClientImpl(credentials);
Date startTime = DateTime.now().minusMinutes(30).toDate();
Date endTime = DateTime.now().toDate();
//DateTime must be in below format
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
String startInterval = dateFormat.format(startTime);
String endInterval = dateFormat.format(endTime);
String timespan = startInterval + "/" + endInterval;
Period interval = Period.minutes(1);
String metricNames = "Egress";
String aggregation = "Total";
Integer top = null;
String orderby = null;
String filter = null;
String metricNamespace = null;
ResponseInner response = clientImpl.metrics().list(resourceId, timespan, interval, metricNames, aggregation,
top, orderby, filter, null, metricNamespace);
List<MetricInner> value = response.value();
for (MetricInner metric : value) {
System.out.println("id " + metric.id());
System.out.println("name " + metric.name().value());
System.out.println("type " + metric.type());
System.out.println("unit " + metric.unit());
List<TimeSeriesElement> timeseries = metric.timeseries();
timeseries.forEach(ts -> {
ts.data().forEach(dt -> {
System.out.println(dt.timeStamp() + "--" + dt.total());
});
});
}
}
By using above I am able to read the metrics values at storage account level, but how can I find the metrics at container level? e.g. if I have 3 containers inside my storage account, I need to find the metrics for each container instead for complete storage account.
Please suggest if there are other ways to find metrics at container level.
There is not direct way of doing this, but one can achieve this by configuring monitoring for the storage account. Follow the below link to configure monitoring,
https://learn.microsoft.com/en-us/azure/storage/common/storage-monitor-storage-account
Once storage account is configured for monitoring, it will create a new container with name $logs in your storage account. This new container is not visible in azure portal but you can view and explore this new container using Azure Storage Explorer tool. The link to download the tool is given below.
https://azure.microsoft.com/en-us/features/storage-explorer/
The logs inside the $logs container are segregated on the basis of date and time in separate folders.
/blob/yyyy/MM/dd/HHmm/000000.log
/blob/yyyy/MM/dd/HHmm/000001.log
where mm is always going to be 00.
The schema for logs can be found in azure documentation at location.
https://learn.microsoft.com/en-us/rest/api/storageservices/storage-analytics-log-format
One can read the log file using the schema format and create useful metrics out if it.
I am making an android application using IMDB open-source api (My movie api).
Features are:
when user search a particular movie they got the list in list view. If they click on a list it shows full details of the movie.
User also can add any movie to favourite list and also can delete it.
Everything works fine. BUT THE APPLICATION FORCE CLOSES IF ANY FIELD IS MISSING FOR A MOVIE ON IMDB DATABASE LIKE MOVIE LANGUAGE OR DURATION ETC.
I have tried if- else syntax but not worked. If have any suggestion please let me know. I will be thankful to you.
Here is my code:
ImageProvider Ip = new ImageProvider();
final String Title = getIntent().getStringExtra("title");
final String story = getIntent().getStringExtra("story");
final String actors = getIntent().getStringExtra("actors");
final String lang = getIntent().getStringExtra("lang");
final String Id = getIntent().getStringExtra("ID");
final String duration = getIntent().getStringExtra("time");
final String directBy = getIntent().getStringExtra("director");
final String year1 = getIntent().getStringExtra("year");
final String src = getIntent().getStringExtra("img");
Log.v("src", src);
title.setText(Title);
details.setText(story);
cast.setText(actors);
language.setText(lang);
mid.setText(Id);
time.setText(duration);
Director.setText(directBy);
year.setText(year1);
VImg.setImageBitmap(Ip.fetchImage(src));