Programmatically share the text in BBM blackberry - blackberry

I need to share my text in BBM, i have tried this code
protected void sendBBM() {
BlackBerryMessenger bbm = BlackBerryMessenger.getInstance();
int moduleHandle = CodeModuleManager.getModuleHandle("net_rim_bb_qm_peer");
ApplicationDescriptor[] apDes = CodeModuleManager.getApplicationDescriptors(moduleHandle);
try {
ApplicationManager.getApplicationManager().launchApplication("net_rim_bb_qm_peer");
} catch (ApplicationManagerException e) {
e.printStackTrace();
}
}
it's going to BBM menu in simulator. but, when i run in my 9300 Mobile it's going to catch statement(Error starting null: null), and BBM is not opening.
Can anyone provide some solutions to solve this issue?

Related

Flutter connectivity: Works on Android, but on iOS simulator when I can open webpages in Safari I have internet but the app says there is no internet?

I use this package: https://pub.dev/packages/connectivity_plus
I have a finished application that is working on Android but when I am testing it on iOS it shows that there is no internet. I can use and open pages in Safari so there is definitely one. But the following code returns false in iOS:
class InternetConnectivity with ChangeNotifier {
StreamSubscription<ConnectivityResult>? _subscription;
bool haveInternet = false;
void checkConnectivity() {
if (_subscription == null) {
_subscription = Connectivity().onConnectivityChanged.listen((ConnectivityResult result) {
bool res = result == ConnectivityResult.mobile || result == ConnectivityResult.wifi;
setHaveInternet = res;
});
}
}
set setHaveInternet(bool value) {
if (haveInternet != value) {
haveInternet = value;
notifyListeners();
}
}
}
I don't get any errors so I don't really know where to look for the problem.
On the screen where it checks that internet connection starts with this:
bool _haveInternet = true;
then in initState() I set the value of it:
#override
void initState() {
super.initState();
InternetConnectivity ? _internetConnectivity = InternetConnectivity();
setState(() {
_haveInternet = _internetConnectivity!.haveInternet;
});
After the initState() ran, the _haveInternet becomes false, so the connectivity_plus package returns false while normally it should be true.
Thanks in advance.
The package has a bug. According to documentation it should only affect iOS simulator. https://github.com/fluttercommunity/plus_plugins/issues/479
From package comments:
/// On iOS, the connectivity status might not update when WiFi
/// status changes, this is a known issue that only affects simulators.
/// For details see https://github.com/fluttercommunity/plus_plugins/issues/479.

how to check internet connection in java in blackberry

I want to check whether internet connection is there or not in blackberry device so that depending on the result I can call webservices to get data or upload data from my application
I have tried this one
CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS))) ||
(CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_BIS_B)) != false
If you want to check the internet connection, then send any url to the web service and check the HTTP Response. If HTTPResponse is 200 then only you are having internet connection. Do like this.......
try
{
factory = new HttpConnectionFactory();
url="Here put any sample url or any of your web service to check network connection.";
httpConnection = factory.getHttpConnection(url);
response=httpConnection.getResponseCode();
if(response==HttpConnection.HTTP_OK)
{
callback(response);
}else
{
callback(response);
}
} catch (Exception e)
{
System.out.println(e.getMessage());
callback(0);
}
Here "response"=200 then you have an internet connection. otherwise it is a connection problem. You can check this like below...........
public void callback(int i)
{
if(i==200)
{
//You can do what ever you want.
}
else
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
int k=Dialog.ask(Dialog.D_OK,"Connection error,please check your network connection..");
if(k==Dialog.D_OK)
{
System.exit(0);
}
}
});
}
}
Here System.exit(0); exit the application where ever you are.
Take these two classes
1)HttpConnectionFactory.java
2)HttpConnectionFactoryException.java
from this link:HttpConnection Classes

Showing the location in Windows Phone 7 works in the emulator but not on the real phone

I have code that is used to show a device's location. It works just fine on the emulator and it takes me to the fake location at Microsoft. But it didn't work when I build it into the phone, it showed me the world map. Is this a known bug or I have done something wrong? Here is my code:
private GeoCoordinateWatcher loc = null;
private void button1_Click(object sender, RoutedEventArgs e)
{
if (loc == null)
{
loc = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
loc.StatusChanged += loc_StatusChanged;
}
if (loc.Status == GeoPositionStatus.Disabled)
{
loc.StatusChanged -= loc_StatusChanged;
MessageBox.Show("Location services must be enabled on your phone.");
return;
}
loc.Start();
}
void loc_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (e.Status == GeoPositionStatus.Ready)
{
Pushpin p = new Pushpin();
p.Template = this.Resources["pinMyLoc"] as ControlTemplate;
p.Location = loc.Position.Location;
mapControl.Items.Add(p);
map1.SetView(loc.Position.Location, 17.0);
loc.Stop();
}
}
}
Instead of using the StatusChanged event, you should use the GeoCoordinateWatcher.PositionChanged event, in from which you should use the GeoPositionChangedEventArgs.Position property, to reflect the changed location.
This is due to my location doesn't support by Bing Map. I couldn't use the Bing Map app installed in my phone neither. Hmm...

Problems opening http connection from blackberry simulator

I'm having trouble when opening a simple HttpConnection from the simulator, I've have appended the deviceside=true suffix to my url, however it's still not working, I'm receiving an empty httpconnection with response code of 0. This is the code that's giving me problems:
public void readUrl(){
HttpConnection conn=null;
try {
conn = (HttpConnection) Connector.open("http://www.google.com;deviceside=true");
conn.setRequestMethod("GET");
if(conn.getResponseCode()==HttpConnection.HTTP_OK){
System.out.println("Create connection sucessfully");
}
} catch (ConnectionNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
DataInputStream din=null;
ByteVector responseBytes=null;
try {
din = conn.openDataInputStream();
responseBytes = new ByteVector();
int i = din.read();
while (-1 != i) {
responseBytes.addElement((byte) i);
i = din.read();
}
} catch (IOException e) {
//TODO: HANDLE EXCEPTIONS
e.printStackTrace();
}
responseBytes.toArray();
I have no idea what's going on. It supposed that by appending the deviceside=true it should connect directly. Anyway I tried too installing the MDS server and setting my url to deviceside=false, but the result was the same.
Now I tested the same code using a local url like http://localhost:8080/resources/mypage.html, and It worked as expected, so I was wondering if this could be a simulator configuration issue. How can I solve it?
Thanks a lot.
In my experience, you need to append ;deviceside=true when using the MDS simulator. There's a great post on the blackberry.com forums that shows you how to determine what connection suffix you should be using, as well as some general good advice on using connections in BlackBerry.
For something to help make it easier to get the content of your request, you can use the IOUtilities class:
InputStream stream = conn.openInputStream();
String contents = new String(IOUtilities.streamToBytes(stream));
";deviceside=true" is for DIRECT TCP transport. To use MDS transport you need to append with ";deviceside=false".
When you run on the device simulator you can use DIRECT TCP transport without the need of starting the MDS simulator. However if you want to test MDS transport, then you need to start MDS simulator before you start the device simulator.
In the Simulator setup tabs "General" do you have the "Launch MDS-CS with simulator" checked?
If so, you do not need to append any suffix at all...
Yes you're right, with deviceside=true the internet connection was used, however it seemed like it was a problem whit the HttpConnection class, when I used this code instead:
public StreamConnection openConnection(){
StreamConnection conn=null;
try {
conn = (StreamConnection) Connector.open(url+";deviceside=true");
//conn.setRequestMethod(httpMethod);
} catch (ConnectionNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
return conn;
}
It worked correctly, so I was wondering something...when opening a connection in blackberry where I should put my code for checking the response code. After creating the connection? like the code above or after opening a dataStream like:
din = conn.openDataInputStream();
responseBytes = new ByteVector();
int i = din.read();
while (-1 != i) {
responseBytes.addElement((byte) i);
i = din.read();
}
Thanks.

BlackBerry logger

I am writing a text file on the BlackBerry simulator using the following code. My data is written successfully to the file but I am not able to find my file. Where can I can find my file on the simulator?
public static void debug() {
OutputStream os = null;
FileConnection fc = null;
try {
String data = "Hello This is Yogesh working on blackberry";
Dialog.alert("TEST_1");
fc = (FileConnection)Connector.open("file:///SDCard/test.txt",Connector.READ_WRITE);
//fc = (FileConnection)Connector.open("file:///SDCard/BlackBerry/pictures/test.txt",Connector.READ_WRITE);
Dialog.alert("TEST_2");
//FileConnection fc = (FileConnection)Connector.open(System.getProperty("file:///SDCard/"+"test.txt"),Connector.READ_WRITE);
Dialog.alert("TEST_3");
if(!fc.exists()) {
Dialog.alert("TEST_31");
fc.create();
}
Dialog.alert("TEST_4");
os = fc.openOutputStream();
Dialog.alert("TEST_5");
os.write(data.getBytes());
Dialog.alert("TEST_6");
Dialog.alert("Data written successfully...!!!");
} catch(Exception e) {
Dialog.alert("Exception in writing logs :"+e);
} finally {
if(os != null) {
try {
os.close();
} catch(Exception e) { }
}
if(fc != null) {
try {
fc.close();
} catch(Exception e) { }
}
}
Within the simulator, if you open the Files application, in the 'Applications' folder, you can navigate through the SDCard files, by selecting File Folders, and then Media Card.
From within the simulator you can also go to Media, click the menu button, select Explore and browse to your file.
Another option is to set your simulator to save the content to a chosen location on the file system: in Eclipse go to Run -> Debug Configurations -> Simulator tab -> Memory tab. Check the "Use PC file system for SD Card files" option and browse to your preferred location. I found this to be very convenient.
Hope this helps :)

Resources