How to show the disk name and capacity of external storage in android - android-external-storage

I am creating an android application that had to work with the external storage.I want to display the list of external storage devices with its external storage name and its free space and its total space can any one tell me how to display capacity and free space and name of a disk in android.
I did some thing to check external devices in a list view:
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) {
Devices_Temp++;
i += "\n" +
"DeviceName: " + device.getDeviceName() +"\n"+
"VendorID: " + device.getVendorId() +"\n" +
"ProductID: " + device.getProductId() + "\n";
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
StatFs statfs = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytes_available = (long)statfs .getBlockSizeLong()*(long)statfs.getAvailableBlocksLong();
long total_bytes_count=bytes_available/(1024*1024);
String_Array_Dynamic_Genaration.add("Free space : "+total_bytes_count);
}

Related

WebUI.getText() returns empty String

I want to get the text of my TestObject, I use WebUI.getText(). My code works fine for one of my pages but fails for another page. I can't figure out why it fails, everything is literally the same and it should not fail. This is what I am doing:
#Keyword
public boolean verifyIPAddr(Socket socket){
//create test object for the ip header
TestObject ipHeader = new TestObject().addProperty("id", ConditionType.EQUALS, 'ipaddr-in-header')
WebUI.waitForElementPresent(ipHeader, 20, FailureHandling.OPTIONAL)
//get text (IP) from ipHeader
String ipHeaderStr = WebUI.getText(ipHeader)
KeywordUtil.logInfo("ipHeaderStr: " + ipHeaderStr.toString())
//split the ipHeaderStr so that "IP: " portion can be removed and only "0.0.0.0" portion is left
String[] ipHeaderStrArr = ipHeaderStr.split(' ')
//store the ip in a variable
String guiIPAddress = ipHeaderStrArr[1]
//get the socket side ip
String cassetteIP = socket.getInetAddress().getHostAddress()
KeywordUtil.logInfo(" address:" + cassetteIP)
//validate that both are the same
if(cassetteIP.equals(guiIPAddress)){
KeywordUtil.logger.logPassed(guiIPAddress + " IP from GUI matches: " + cassetteIP + " from socket")
return true;
}
else{
KeywordUtil.logger.logFailed(guiIPAddress + " IP from GUI does not match: " + cassetteIP + " IP from socket")
return false
}
}
]2
I am 100% it has something to do with WebUI.getText() but it's confusing me because it works for one page but fails for the other.
The following is the HTML for the working page:
The following is the HTML for the page that is not working:
Update:
I just noticed that the one that was failing, fails sometimes and sometimes it passes, I still want to know how I can guarantee the behavior to stay stable.
There are a couple of things you can try:
You can add a delay before getting the text of the element:
WebUI.delay(30)
You can prolong the wait
WebUI.waitForElementPresent(ipHeader, 60, FailureHandling.OPTIONAL)
The reason is, Katalon (Selenium) code often depends on elements outside of its sphere of influence, like load times, network traffic, computer hardware, competing race-conditions, etc.
So, even with same code, sometimes the wait times will differ and that's why it is better to use flexible waits (like waitForElement*() methods).

Am I missing something basic? Personality Insights

So this is the first time using any of bluemix service, and I'm getting the following error and can't find any help online relating to this.
Am I missing something basic with set up?
Any help is appreciated, thanks.
Error is:
> Error: Could not find or load main class
> com.ibm.watson.developer_cloud.personality_insights.v3.Main
Screen shot: http://imgur.com/a/ArkP6
Code:
package com.ibm.watson.developer_cloud.personality_insights.v3;
import com.ibm.watson.developer_cloud.personality_insights.v3.model.Profile;
public class Main {
public static void main(String[] args) {
System.out.println("kek");
PersonalityInsights service = new PersonalityInsights("2016-10-19");
service.setUsernameAndPassword(Blanked);
// Demo content from Moby Dick by Hermann Melville (Chapter 1)
String text = "Call me Ishmael. Some years ago-never mind how long precisely-having "
+ "little or no money in my purse, and nothing particular to interest me on shore, "
+ "I thought I would sail about a little and see the watery part of the world. "
+ "It is a way I have of driving off the spleen and regulating the circulation. "
+ "Whenever I find myself growing grim about the mouth; whenever it is a damp, "
+ "drizzly November in my soul; whenever I find myself involuntarily pausing before "
+ "coffin warehouses, and bringing up the rear of every funeral I meet; and especially "
+ "whenever my hypos get such an upper hand of me, that it requires a strong moral "
+ "principle to prevent me from deliberately stepping into the street, and methodically "
+ "knocking people's hats off-then, I account it high time to get to sea as soon as I can. "
+ "This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself "
+ "upon his sword; I quietly take to the ship. There is nothing surprising in this. "
+ "If they but knew it, almost all men in their degree, some time or other, cherish "
+ "very nearly the same feelings towards the ocean with me. There now is your insular "
+ "city of the Manhattoes, belted round by wharves as Indian isles by coral reefs-commerce surrounds "
+ "it with her surf. Right and left, the streets take you waterward.";
ProfileOptions options = new ProfileOptions.Builder().text(text).build();
Profile profile = service.profile(options).execute();
System.out.println(profile);
}
}
This sounds like a class path problem. Did you specify the jar with this class to be on your classpath when you run it (aka java -cp...)?

adding params to joomla plugin based on external file

I am trying to develope a simple joomla plugin and i have a question, if you kindly could help me.
I have a long list of constants to use in my plugin, a group is to use with a joomla version and another group to use with another version, like this
//joomla version 2.5
$a01 = " some value "
$a02 = " some value "
$a03 =" some value "
....
....
$a99 = " some value "
//joomla version 3.0
$b01 = " some value "
$b02 = " some value "
$b03 = " some value "
....
....
$b99 = " some value "
In my plugin file i have this code:
if (!version_compare(JVERSION, '3.0', 'ge'))
{
// do something using constants for version less than 3.0
} else {
// do something using constants for version more than 3.0
}
For a better reading and organization where can hold those constants? In same file or in another file like (params or constants)? Which is the best approach? And how could i implement it?
What about placing it in a db-table? You retrieve them in your plugin by:
$db=JFactory::getDbo();
$db->setQuery('select key, value from #__yourtable where version ='.$version);
$list=$db-loadAssocList();
foreach($list as $v){
eval("define({$v['key']}, {$v['value']});");
}
Now all your constants for version $version are loaded.
...and if you want to be able to manage your constants from the joomla backend interface you could use a component-creator to quickly create this simple table with a full editing interface ( try component-creator.com )
regards Jonas (not affiliated with component-creator.com :) )

Read/Write from a hdd inside a network device driver (Linux)

I am new in Linux programming. I want to customize an existing driver for my needs. It is the RealTek 8169 network driver.
My question is: I can access to a HDD inside the driver? Is this "allowed"? Or could I get some problems with this?
I want to do something like this:
// Which disk?
char diskName[] = "/dev/sda";
std::string diskError = std::string() + diskName + ": ";
// Open device file
std::ifstream disk(diskName, std::ios_base::binary);
if(!disk)
throw(std::runtime_error(diskError + std::strerror(errno)));
// Seek to 12345'th sector
disk.seekg(512 * 12345);
if(!disk)
throw(std::runtime_error(diskError + std::strerror(errno)));
// Read in one sector
std::vector<char> buffer(512);
disk.read(&buffer[0], 512);
if(!disk)
throw(std::runtime_error(diskError + std::strerror(errno)));

Push Notification showing localization constant instead of message

I have a serious problem I have not found any questions about on the net. When I push a localized message it only works for Swedish and not English. I have another that says that it only shows a constant for their Swedish Iphone 4. I have also tested on Iphone 3g and it has the same problem as my iphone 4, works in swedish not in english.
When displaying a popup for Iphone 4 in English, I only get the localization key I supply in my notification from the server.
Here is the string of the notification in C# that I push from a Windows Server. The extra parameters for my iphone app works totally fine in any language so it seems it has nothing to do with the server side part of the push.
int total = notification.AmountScheduledEvent + notification.AmountCourseResult + notification.AmountExam;
string locKey = (total > 1 ? "PushMessageMultiple" : "PushMessageSingle");
string msg = "{\"aps\":{"+
"\"alert\": {"+
"\"loc-key\":\"" + locKey + "\","+
"\"loc-args\":[\"" + total + "\"]},"+
"\"badge\":" + total + ","+
"\"sound\":\"default\"},"+
"\"amountSchedule\":" + notification.AmountScheduledEvent + ","+
"\"amountCourseResult\":" + notification.AmountCourseResult + ","+
"\"amountExam\":" + notification.AmountExam + "}";
In my Localizable.strings in sv.lproj:
/* push stuff */
"PushMessageMultiple" = "%# nya händelser";
"PushMessageSingle" = "1 ny händelse";
In my Localizable.strings in en.lproj:
/* push stuff */
"PushMessageMultiple" = "%# new events";
"PushMessageSingle" = "1 new event";
Here is a picture of the screen with a notification that works (Swedish)
http://img267.imageshack.us/i/img0014b.png/
Here is a picture of the screen with a notification that doesn't work (English)
http://img696.imageshack.us/i/img0015i.png/
Any idea why I get a constant instead of a message?
Try to use:
NSLocalizedString(#"PushMessageMultiple",#"");
This will dynamicaly get the correct string.