FileConnection on Storm 9550 - blackberry

I'm using the following code to create a file and write data into it:
fileName = "file:///store/home/user/myapp/groups.xml";
try {
fc = (FileConnection) Connector.open(fileName, Connector.READ_WRITE);
if (!fc.exists())
fc.create();
os = fc.openDataOutputStream();
String XMLString = "blablabla";
byte[] FinalXML = XMLString.getBytes();
os.write(FinalXML);
os.close();
fc.close();
} catch (IOException e) {
Dialog.alert(e.getMessage());
}
It works good on my bb 9700 with OS6 and on 9700 simulator. But it doesn't work on 9550 device and simulator. I'm getting IOException. The message says
File not found
Does anybody have some voodoo magic that will help me?

Looks like the folder "file:///store/home/user/myapp/" does not exist yet. Just check for its presence first, if not present - create and then go on with rest of your code.
BTW, the "file:///store/home/user/" path is valid for all mentioned devices.

IOExeption go if the firewall disallows a connection that is not btspp or comm. so you have to add permission for your program such as FILE_API ..... you can read book : Advance BB dev to do this

Related

Read text from an URL on Codename One

I'm relatively new to codename one. I'm trying to read text from a pure text url and store the text in a string. I tried using the java IO package but for some reason it doesn't seem to wirk with codename one. Please help.
David.
I think you might not really understand codenameone seeing as you tried to use the Java IO package. But anyway, this code might get you along
ConnectionRequest r = new ConnectionRequest();
r.setUrl("YOURURLHERE");
r.setPost(false);
r.addResponseListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
try
{
NetworkEvent event = (NetworkEvent) ev;
byte[] data= (byte[]) event.getMetaData();
String decodedData = new String(data,"UTF-8");
System.out.println(decodedData);
} catch (Exception ex)
{
ex.printStackTrace();
}
}
});
NetworkManager.getInstance().addToQueue(r);
NOTE: Instead of using System.out.println, which works fine for debugging purposes, you probably want to add the text to your application with a GUI component. I'm not sure if this needs to be said, but it won't do any harm stating it again :)

How to switch from one app to another app at run time

Is there any possibility to switch from one application to another application at run time using Appium.
Thanks
Finally I found accurate answer, May it will be usefull for some one
source https://www.linkedin.com/grp/post/6669152-6027319885992841219?trk=groups-post-b-title
// App1 capabilities
String calculatorAppPackageName="com.android.calculator2";
String calculatorAppActivityName="com.android.calculator2.Calculator";
// App2 capabilities
String settingsAppPackageName="com.android.settings";
String settingsAppActivityName="com.android.settings.Settings";
#Before
public void setUp() throws MalformedURLException
{
DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "192.168.215.101:5555");
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, calculatorAppPackageName);
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, calculatorAppActivityName);
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testApp() throws InterruptedException, MalformedURLException
{
//Perform calculation in calculator
driver.findElement(By.name("4")).click();
driver.findElement(By.name("×")).click();
driver.findElement(By.name("3")).click();
driver.findElement(By.name("=")).click();
//launch settings App
driver.startActivity(settingsAppPackageName, settingsAppActivityName);
//Switch OFF WIFI
driver.findElement(By.id("com.android.settings:id/switchWidget")).click();
//Re launch calculator App
driver.startActivity(calculatorAppPackageName, calculatorAppActivityName);
//Validate results
String result = driver.findElement(By.className("android.widget.EditText")).getText();
System.out.println("Result : " + result);
Assert.assertEquals("Incorrect Result", "12", result);
}
You can change applications by re-instantiating the webdriver with the new application's attributes.
driver = webdriver.Remote(appiumUrl,dcapabilityApp1)
[Your tests]
driver = webdriver.Remote(appiumUrl,dcapabilityApp2)
[New app tests]
As long as you don't close/disconnect the emulator/simulator/device then your user data will be maintained.
You can use:
driver.startActivity(settingsAppPackageName, settingsAppActivityName);
to invoke another app withing the same code.
Going through question , i have an assumption that it might break your driver current session.and if the driver command failed there is no fall back for it.
Can't it been done with adb command .
One can use above solution or might use abd command
adb shell am start -d <YOUR_ACTIVITY_NAME>
And this will open directly appActivity without fail.
driver.startActivity() method can be used to switch between apps. For more details how it works you can check below video.
Watch "Appium Tutorial- Switching between apps (Contact and SMS)" on YouTube
https://youtu.be/sH1bHeDDj8U

Adobe air Native Process only works in the flash environment, but when deployed i get Error #3219

I've been trying to use ffmpeg with an air app that I made in flash cs5.5. I have it so that ffmpeg.exe needs to be located in the directory where the air app is installed (File.applicationDirectory.nativePath).
For some reason this only works when I run the program through the flash dev environment. But when I actually deploy the app, I get error #3219:The NativeProcess could not be started. ffmpeg.exe is located in the same folder.
I actually don't know the full message that it gives...not sure what the property of the error that will give me that message when I catch it. All I know is that it's error 3219.
Would this be a profile issue? If i didn't have the extended desktop desktop profile, I don't think I would be able to get this error, I'd get a profiling error wouldn't I?
I've disabled user access control as well...I'm using windows 7.
So I'm the OP, and I just realized that you can't use native process calls if you do not install the air application through the exe installer, which is an option in publish settings. I've been using the air installer.
one thing to mention is that (I'm sure you already know) the NativeProcess works only on that OS where it was compiled, so if you compile on a windows box your NativeProcess will only work on windows and not on unix/mac.
I don't know how you call the native process, but here is a code snippet that I extracted of one of my working Classes, maybe comparing it with your aproach it will give you some hint to find the problem :)
import flash.desktop.*;
import flash.errors.*;
import flash.events.*;
import flash.filesystem.*;
public function execute():void
{
var executablePath:String = "C:\ffmpeg.exe";
var parametersString:String = "-i input.avi -b 64k output.avi";
if(NativeProcess.isSupported) {
var args:Vector.<String> = new Vector.<String>();
var file:File = new File(String(executablePath));
var parameters:Array;
parameters = parametersString.split(" ");
for each ( var parameter:String in parameters ) {
args.push(parameter);
}
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.arguments = args;
startExecution(nativeProcessStartupInfo);
}
private function startExecution(nativeProcessStartupInfo:NativeProcessStartupInfo):void
{
var nativeProcess:NativeProcess = new NativeProcess();
nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, onExitError);
var msg:String = "";
try {
nativeProcess.start(nativeProcessStartupInfo);
trace("Trying to start process");
} catch (error:IllegalOperationError) {
trace("Illegal Operation: "+error.toString());
} catch (error:ArgumentError) {
trace("Argument Error: "+error.toString());
} catch (error:Error) {
trace("Error: "+error.toString());
}
if (nativeProcess.running) {
trace("Native Process Support");
}
}
public function onExitError(event:NativeProcessExitEvent):void
{
trace("Native Process Exit code: "+event.exitCode);
}

How to properly build HTTP connection suffix

I have written code to get a location name using Google Maps reverse geocoding, for example:
http://maps.google.com/maps/geo?json&ll=9.6,73.7
How can I add an appropriate HTTP connection suffix to the above URL?
I have tried the following function:
private static String getConnectionStringForGoogleMap(){
String connectionString="";
if(WLANInfo.getWLANState()==WLANInfo.WLAN_STATE_CONNECTED){
connectionString="&interface=wifi";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_MDS) == CoverageInfo.COVERAGE_MDS){
connectionString = "&deviceside=false";
}
else if((CoverageInfo.getCoverageStatus() & CoverageInfo.COVERAGE_DIRECT)==CoverageInfo.COVERAGE_DIRECT){
String carrierUid=getCarrierBIBSUid();
if(carrierUid == null) {
connectionString = "&deviceside=true";
}
else{
connectionString = "&deviceside=false&connectionUID="+carrierUid + "&ConnectionType=mds-public";
}
}
else if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
{
}
return connectionString;
}
When I run the application in the simulator, I create the URL like this:
http://maps.google.com/maps/geo?json&ll=9.6,73.7+getConnectionStringForGoogleMap();
But I get a tunnel exception and am not sure what to do next.
This URL also leads to an exception:
http://maps.google.com/maps/geo?json&ll=9.6,73.7&deviceside=false&ConnectionType=mds-public
As does:
http://maps.google.com/maps/geo?json&ll=9.6,73.7;deviceside=false;ConnectionType=mds-public
I am confused about what to do to get this to work.
You definitely want semi-colons (;) and not ampersands (&). Are you tring to run this on the simulator? If so, do you have the MDS simulator running? That is required in order to use devicside=false on the simulator.
Try using Versatile Monkey's networking helper class to find the best path for your HTTP connection and avoid those tunnel exceptions. And form the URL with the correct syntax.
There is a very good posting about this on the BlackBerry Java development forum, complete with sample HTTP connection code.
Try using following
It worked for me
http://maps.google.com/maps/geo?json&ll=9.6,73.7&;deviceside=false;ConnectionType=mds-public
If you are targeting OS5 and above you can use ConnectionFactory. This takes a lot of the hard work out of establishing the correct connection type.

FOP: how to specify image src relative path?

This is my first question here, i hope i'm doing it right. Sorry for my bad English in advance :)
I am using JSF 2.0 (Eclipse IDE) and i'm trying to generate some PDF files using Apache FOP 1.0.
I was able to make simple PDF files using instructions on Apache Fop site , but i can't insert any image from my application folder. My folder structure is like this:
In my application WebContent i have (among else)
pdf_transform/xslt/transformFile.xsl, and
pdf_transform/xslt/logo.jpg
In transformFile.xsl i have
<fo:block><fo:external-graphic src="url('logo.jpg')"/></fo:block>
but when i clik 'showPDF' button in my servlet, i get PDF file without image (everything else is there), and this messages in console:
SEVERE: The Source that was returned
from URI resolution didn't contain an
InputStream for URI: logo.jpg Nov 18,
2010 5:16:49 PM
org.apache.fop.events.LoggingEventListener
processEvent SEVERE: Image not found.
URI: logo.jpg. (No context info
available)
I tried to use 'logo.jpg' instead of url('logo.jpg'), putting image on various places inside WebContent folder and using different navigation("./logo.jpg") but it didnt work.
It works fine if i set absolute path (for example "d:/fop/images/logo.jpg") but i need resurces whitin my application.
While searching, i found that this is related to fopFactory.setURIResolver() and/or userAgent.setBaseURL(). Tried something with that, but didnt succeed.
I am new to both JSF and FOP, and this image situation has been bothering me quite a while. Can someone help me with this, or at least direct me to some tutorial on "how to configure FOP for relative path use"?
EDIT: I don't want any absolute paths and app should work independently of its location on computer (to be publishable). My search tells me it has something to do with configuring FOP, but i don't know how to do it :)
Thanks in advance.
P.S. This is method which is called to display PDF:
public void printExchangeRateList(ActionEvent event) {
BufferedOutputStream output = null;
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
String path = externalContext.getRealPath("/");
try {
response.reset();
response.setHeader("Content-Type", "application/pdf");
output = new BufferedOutputStream(response.getOutputStream(), 10240);
File xsltfile = new File(path+"/pdf_transform/xslt/transformFile.xsl");
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, output);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(new StreamSource(xsltfile));
Source src = new DOMSource(makeXML()); // my method
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
} finally {
if (output != null) output.close();
/*try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
} catch (Exception e) {
// TODO Auto-generated catch block
}
facesContext.responseComplete();
}
i found solution to my problem. I thought i tried that, but it seems i made some little mistake back then. Anyway, with the following code
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
String basePath = externalContext.getRealPath("/");
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setBaseURL(basePath);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
foUserAgent.setBaseURL(fopFactory.getBaseURL());
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, output); // for some output
you can access your images (and other resources) from your xslt file using relative path starting from your application's WebContent folder. In my case, i can access logo.jpg like this
<fo:external-graphic src="url('pdf_transform/xslt/logo.jpg')"/>
Took me time to figure out this, i don't get it why no examples with such basic thing on the net (or i can't find them :)
Note: In FOP 2.0 there is no setBaseURL() method. Instead you pass the base URL as a parameter to FopFactory.newInstance(). Many of the other setters have been moved to FopFactoryBuilder.
If you have access to the web url for the pictures you can use that as well when generating reports, ie http://localhost/images/logo.jpg .
But while I still had images locally on the web server, I included the path to the application in the XML file and used it like this:
<xsl:variable name="base_path" select="base-path"/>
<xsl:variable name="logo" select="companies/company/logo"/>
<fo:external-graphic src="url({$base_path}{logo})"/>
Where the XML structure might be something like this:
<?xml version="1.0" encoding="UTF-8"?>
<base-path>/path/to/app/</base-path>
<companies>
<company>
<logo>images/company1.jpg</logo>
</company>
<company>
<logo>images/company2.jpg</logo>
</company>
</companies>
I had the same problem and tried this solution:
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
Request request = RequestCycle.get().getRequest();
//sort of a hack to find the path to the files that are in /img folder.
String baseUrl = request.getUrl().getProtocol()+"://"+request.getUrl().getHost()+":"+request.getUrl().getPort();
foUserAgent.setBaseURL(baseUrl);
Then, on XSL I used:
<fo:external-graphic src="/img/image.png" />
To test if this is working, you should be able to see the image on protocol://link:port/img/image.png

Resources