Restarting Blackberry Programmatically - blackberry

I want to make Blackberry application that can restart the blackberry it self (after doing some task)
for example, i make this little application using the dummy
dummy : (after it becomes dummy.cod, i move it to the res folder and rename it to dummy, not using .cod anymore)
public class Dummy extends Application{
public static void main( String[] args ) {
new Dummy().enterEventDispatcher();
}
public Dummy(){
}
}
application sample code :
(description of my application : just have 1 button to call the reset method)
public void reset() throws Exception {
// load the dummy cod file
byte[] cod = IOUtilities.streamToBytes(getClass().getResourceAsStream("/dummy"));
// create new module
int newHandle = CodeModuleManager.createNewModule(cod.length, cod, cod.length);
// install the module
if (newHandle != 0) {
int savecode = CodeModuleManager.saveNewModule(newHandle, true);
if (savecode == CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
Logger.debug("The operation completed successfully; a module was overwritten and marked for deletion in the process.");
// now run the dummy application in background
ApplicationDescriptor appDesc = CodeModuleManager.getApplicationDescriptors(newHandle)[0];
ApplicationManager.getApplicationManager().runApplication(appDesc, false);
CodeModuleManager.deleteModuleEx(newHandle, true);
}
// restart the blackberry if required
CodeModuleManager.promptForResetIfRequired();
}
When I run my code to Simulator (SimPackage 6.0.0.587 - 9780 & SimPackage 5.0.0.977 - 9300) the code was running well, it shows a message to "Restart Now / Restart Later".
But when I’ve load my code to real device 9780 OS 6.0.0.570 and device 9300 OS 5.0.0.846, the code is still won’t work.
Any idea why is it happen ? or I just make a simple but fatal mistake ?
Thanks :)

Your code is correct, but you need to sign your code to be able to execute CodeModuleManager.deleteModuleEx on a real device.
Please refer to the CodeModuleManager documentation for more information.

Related

Xamarin & Multiple Filepicker

i'm building a project on Xamarin. Right now i have a big issue. I need to browse user's computer for upload any file. He can of course upload multiple files. As i know Xamarin does not provide browsing of all the system but just its. So i tried to find a way with some drag n drop, i didn't find. I tried a filepicker but he let me pick just one file (my client would upload 100 files at once) so it doesn't fit to what i need. Finally i decided to do my own browsing system but it takes forever to browse because of the UI. Do you have any solution for me ? I would appreciate a package with a filepicker that allow multiple files.
Thanks
Have you tried the class FileOpenPicker in UWP ?
It supports to pick multiple files , check the method FileOpenPicker.PickMultipleFilesAsync.
Sample
Define interface in Forms project
public interface MyFilePicker
{
Task OpenFilePickerAsync();
}
Implement in UWP project
[assembly: Dependency(typeof(UWPFilePicker))]
namespace App24.UWP
{
class UWPFilePicker : MyFilePicker
{
public async Task OpenFilePickerAsync()
{
var openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
if (files.Count > 0)
{
StringBuilder output = new StringBuilder("Picked files:\n");
// Application now has read/write access to the picked file(s)
}
else
{
return;
}
}
}
}
Call it in Forms project
private async void Button_Clicked(object sender, EventArgs e)
{
MyFilePicker service = DependencyService.Get<MyFilePicker>();
await service.OpenFilePickerAsync();
}

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

How to make a blackberry application start , by code?

I have a background function listening for push messages. I need to handle though the push. I created the function to take any actions when the push arrives and it works pretty well. For example when a push arrives i increment a number etc etc.
However what would be the code to actually make the application start , when the user presses ok to the push?
I just need to make the application start normally , like the user just pressed on the icon of the app.
I am using OS < 7.X
One typical pattern is to build an application that has two entry points. That is, it can be started in two different ways. One way, would be the normal UiApplication. That's the standard BlackBerry app that can be started with a home screen icon press.
The other way would be to define a background service, that handles push notifications, and is started by the OS as soon as the device boots.
You'll define the background/push entry point by adding an Alternate Entry Point in your app's BlackBerry_App_Descriptor.xml file. Make sure to check Auto-run at Startup and Do not display the application icon .... Your app descriptor xml file should then contain something like this, in addition to the normal entry point for the UiApplication:
<AlternateEntryPoints>
<AlternateEntryPoint Title="PushService" MainMIDletName=""
ArgumentsForMain="-push" HomeScreenPosition="0"
StartupTier="7" IsSystemModule="true"
IsAutostartup="true" hasTitleResource="false"
TitleResourceBundleKey="" TitleResourceBundleName=""
TitleResourceBundleClassName="" TitleResourceBundleRelativePath="">
<Icons/>
<KeywordResources KeywordResourceBundleName="" KeywordResourceBundleRelativePath="" KeywordResourceBundleClassName="" KeywordResourceBundleKey=""/>
</AlternateEntryPoint>
</AlternateEntryPoints>
Then, you'll have a main program like this:
public class MyApp extends UiApplication
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("-push")) {
// this is the push service
PushAgent pa = new PushAgent();
pa.enterEventDispatcher();
} else {
// UiApplication
MyApp app = new MyApp();
app.enterEventDispatcher();
}
}
}
Where PushAgent is a class that extends Application, not UiApplication.
Then, when your push agent receives a notification and you decide you want to show the UI, use something like this:
ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();
// String[] used for command line args, but we don't pass any to the UI app
ApplicationDescriptor ui = new ApplicationDescriptor(ad, new String[] { });
ApplicationManager.getApplicationManager().runApplication(ui);
try this -
When you click the ok button use the following code to run your ui application.
public void dialogClosed(Dialog dialog, int choice) {
switch (choice) {
case Dialog.OK:
try {
ApplicationDescriptor[] appDescriptors =CodeModuleManager.getApplicationDescriptors(CodeModuleManager.getModuleHandle("BlackBerryCity")); //here BlackBerryCity is the COD module Name
ApplicationDescriptor appDescriptor = new ApplicationDescriptor(appDescriptors[0], new String[] {"BlackBerryCity"});
ApplicationManager.getApplicationManager().runApplication(appDescriptor);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case Dialog.CANCEL:
break;
default:
break;
}
}
class EntryPointForApplication extends UiApplication {
private static EntryPointForApplication theApp;
public EntryPointForApplication() {
GUIApplication scr = new GUIApplication();
pushScreen(scr);
}
}
Read this also How to setup alternate entry point in Blackberry application?
For sake of completeness here are all the options that you can use to launch an application:
I am assuming that you already have multiple entry points - one for the background listener and one for the UI Application. Also assuming that you are not passing any Application Arguments for the UI App. (See Nate's answer for full description of how to do this.)
Using runApplication() method:
ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor();
// String[] used for command line args, but we don't pass any to the UI app
ApplicationDescriptor ui = new ApplicationDescriptor(ad, new String[] { });
//Launch the application and ask it to come in foreground
ApplicationManager.getApplicationManager().runApplication(ui, true);
Using launch() method:
String modulename = "mymodule";
ApplicationManager.launch(modulename);
Using launchApplication() method:
String modulename = "mymodule";
ApplicationManager.launchApplication(modulename);
One thing to note is that if your UI app is already open, all these methods will simply bring it to foreground in whatever condition it it. If you require the click of button to open a new instance of your app, you will have to pass some random parameter as the application arguments and then ignore it in the main method.

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);
}

running code in remote process CLR runtime through ICLRRuntimeHost and ExecuteInDefaultAppDomain()

I tried to combine the examples at coding the wheel and profiler attach. Everything seems to go fine, except, when I try to enumerate running assemblies in the remote processes' default appdomain, I don't get the right list. public class remoteFoo {
public static int sTest(String message) {
AppDomain currentDomain = AppDomain.CurrentDomain;
Assembly[] assems = currentDomain.GetAssemblies();
MessageBox.Show("List of assemblies loaded in current appdomain:");
foreach (Assembly assem in assems)
MessageBox.Show(assem.ToString()); //remoteFoo gets listed, but not hostBar.
return 3;
}
}remoteFoo gets listed, but not hostBar. Basically I want to use introspection to run code in the remote process's appdomain. But it seems that I don't have the right appdomain...
Here is a link to the code I use: main.cpp

Resources