Critical tunnel failure error blackberry - blackberry

I have developed a app for blackberry ,its approved from appworld but it gives following error
on 4.6
Critical tunnel failure
and
on 5.0 and 6.0
ava.io APN not specified
please help why this error is coming and how to solve it

I think Problem is you didn't add appropriate connection suffix to the url.
Follow the link can solve your problem:http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_make_an_HTTP_or_socket_connection.html?nodeid=826935&vernum=0
And also ou can use the following sample code:
private static String getConnectionString(){
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;
}

Just to clear up some issues.
#Jisson your answer was helpful
But you did not include code for the method getCarrierBIBSUid()
/**
* Looks through the phone's service book for a carrier provided BIBS network
* #return The uid used to connect to that network.
*/
private static String getCarrierBIBSUid()
{
ServiceRecord[] records = ServiceBook.getSB().getRecords();
int currentRecord;
for(currentRecord = 0; currentRecord < records.length; currentRecord++)
{
if(records[currentRecord].getCid().toLowerCase().equals("ippp"))
{
if(records[currentRecord].getName().toLowerCase().indexOf("bibs") >= 0)
{
return records[currentRecord].getUid();
}
}
}
return null;
}
Also it might be helpful to include
if (DeviceInfo.isSimulator()){
return ";deviceSide=true";
}
At the beginning of the getConnectionString() method
For more info see Melick's Blog

Solved this issue by setting the APN values on the phone its self and using the connection string code suggested in the other answers.
Change your APN settings (in South Africa)
On Home screen, click Options
Click Advanced Options and then TCP
Enter the APN: **internet**
username: **guest**
password: **guest**
Press the Menu key and select Save
(for rest of the world find your settings here)
From http://www.blackberrytune.com/blackberry-tcp-ip-apn-settings/
and
http://www.blackberryfaq.com/index.php/Carrier_specific_APN/TCP_settings

Related

Is it possible to remotely control an EA on a PC from another PC?

I have an EA (i.e Robot) i want people to have it on their PC. is it possible to activate or deactivate it from my PC based on their subscription condition? Explanation: if Mr. A has subscribed for this month, i will be the one to activate it from my PC. Meaning, even though the EA is on their system, they won't be able to activate or deactivate it.
You can use your PC (need to make sure that you have a static IP address and then launch a web application). Simpler is to rent a VPS. Then, create a simple web application, probably using Django (Python) or PHP, with REST webservice and admin panel.
EA side: every robot is compiled, EX4 file is provided to a client. Your client adds http://yourwebsite.org/ into list of allowed urls in MT4 then uses the EA. When EA is attached to the chart, OnInit() function is called, use WebRequest() function inside that block to let your EA contact your website and ask whether it can work (probably client may pass login and password, or account number and broker name (with client name if you wish). The webserver receives that data and makes validation.
Another question is how to let your EA to work till some time. Easiest way is to call the webserver once a day (at random time seems better) with the same validation request. If validation fails - EA stops working.
Finally, think of how you are going to deactivate your EA... It might happen that EA opened plenty of deals and pending orders, and if it kills itself with ExpertRemove(), those deals will remain in MT4. So probably it would be better to notify the client that EA is no longer active, and follow the existing orders, close all at breakeven if possible, or other solutions that depends on your EA logic. The following piece of code worked for some clients without any complaints, you are welcome to use it (with your super admin, password if needed, and domain name).
class CLicenseOnline : public CObject
{
private:
string m_login;
string m_password;
datetime m_nextCheck;
int m_prevResult;
string m_url;
int m_strategyId;
public:
CLicenseOnline(const string login,const string password,const int id):
m_login(login),m_password(password),m_nextCheck(0),m_strategyId(id),m_prevResult(-1)
{
bool isCheckingRequired=false;
if(CLicenseOnline::isSuperAdmin(login,password))
{
printf("%i %s - Hello, SUPER ADMIN!",__LINE__,__FILE__);
isCheckingRequired=true;
}
isCheckingRequired= isCheckingRequired || IsTesting();
if(isCheckingRequired)
{
m_nextCheck=INT_MAX;
m_prevResult=1;
}
else
{
m_url=CLicenseOnline::genUrl(login,password);
}
}
~CLicenseOnline(){}
int check()
{
if(TimeCurrent()>m_nextCheck)
{
int result=this.checkMain();
switch(result)
{
case 1: m_nextCheck=this.generateNextDate(); m_prevResult=1;break;
default:
case 0: m_nextCheck=TimeCurrent()+PeriodSeconds(PERIOD_M1); m_prevResult=0;break;
case-1: m_nextCheck=TimeCurrent()+PeriodSeconds(PERIOD_H1); m_prevResult=-1;break;
}
}
return(m_prevResult);
}
static string genUrl(const string login,const string password)
{
const string http="localhost";
return(StringFormat("http://%s/verify/?Login=%s&&Password=%s&&Check=%d",http,login,password,2147483647));
}
static string getHttpResponce(const string url)
{
char data[],res[];
string cookies=NULL, headers=NULL,result;
ResetLastError();
int answer = WebRequest("GET",url,cookies,NULL,5000,data,0,res,headers);
if(answer==200)
{
result = CharArrayToString(res);
return(result);
}
//printf("%i - result=%d|%s|size=%d; %d",__LINE__,answer,result,ArraySize(res),GetLastError());
return(NULL);
}
private:
static bool isSuperAdmin(const string login,const string password)
{
static string
superAdminLogin="Admin",
superAdminPassword="password";
//ATTENTION! Edit the login and password here!
return login==superAdminLogin && password==superAdminPassword;
}
datetime generateNextDate()const
{
return(iTime(_Symbol,PERIOD_D1,0)+PeriodSeconds(PERIOD_D1)+MathRand()%PeriodSeconds(PERIOD_D1));
}
int checkMain()const
{
string respond=CLicenseOnline::getHttpResponce(m_url);
if(respond==NULL)
return(0);//try later
CJAVal js(NULL,jtUNDEF);
if(!js.Deserialize(respond))
{
printf("%i %s - failed to deserialize %s",__LINE__,__FUNCTION__,respond);
return(-1);
}
int retCode=(int)js["key"].ToInt();
switch(retCode)
{
case -1: Alert("incorrect password");return(0);
case -2: Alert("incorrect key!");return(0);
case -3: Alert("incorrect request method!");return(0);
case -4:
case -5: Alert("no such login");return(0);
default:
Alert(StringFormat("%i %s - incorrect login/password/no such user!",__LINE__,__FUNCTION__));
return(0);
case 200:
{
CJAVal *valueJs=js["value"];
if(!this.checkStatus(valueJs["Status"].ToStr()))
return(-1);
if(!this.checkAccount(
(int)valueJs["Allow_account_1"].ToInt(),(int)valueJs["Allow_account_2"].ToInt(),(int)valueJs["Allow_account_3"].ToInt()))
return -1;
bool strategyX=(bool)valueJs["Allow_strategy_"+(string)m_strategyId].ToBool();
if(!stategyX)
{
return(-1);
}
return(1);
}
}
return(-1);
}
bool checkStatus(const string status)const
{ //printf("%i %s - status = |%s|%d",__LINE__,__FUNCTION__,status,IsDemo());
if(status=="demo")
{
if(!IsDemo())
{
string message=StringFormat("your login %s is allowed to trade on Demo accounts only!",m_login);
Alert(message);
printf("%i %s - %s",__LINE__,__FILE__,message);
return(false);
}
return(true);
}
if(status!="active")
{
string message=StringFormat("status of your login [%s] is [%s] so not allowed to trade!",m_login,status);
Alert(message);
printf("%i %s - %s",__LINE__,__FILE__,message);
return(false);
}
return(true);
}
bool checkAccount(const int acc1,const int acc2,const int acc3)const
{
if(acc1==0 && acc2==0 && acc3==0)
return(true);
int currentAccount=AccountNumber();
if(acc1==currentAccount || acc2==currentAccount || acc3==currentAccount)
return(true);
string message=StringFormat("allowed accounts are only %d, %d and %d, your account %d is not allowed!",acc1,acc2,acc3,currentAccount);
Alert(message);
printf("%i %s - %s",__LINE__,__FUNCTION__,message);
return(false);
}
};

Remove password and connect with new password wifi android

i would like to ask your help, this is my code :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==REQUEST_CODE_INPUT){
switch (resultCode){
case RESULT_CODE_PASS:
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
WifiManager wifiManager= (WifiManager) getSystemService(Context.WIFI_SERVICE);
pass=data.getStringExtra("passWord");
nameWifi=data.getStringExtra("nameWifi");
WifiConfiguration conf=new WifiConfiguration();
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
List<ScanResult> networkList=wifiManager.getScanResults();
if(networkList !=null){
for(ScanResult network : networkList){
if(network.SSID.startsWith("\"")){
network.SSID=network.SSID.substring(1, network.SSID.length() - 1);
}
if(nameWifi.equals(network.SSID)){
String Capabilities=network.capabilities;
if(Capabilities.contains("WPA2")){
conf.preSharedKey="\""+pass+"\"";
}else if(Capabilities.contains("WEP")){
conf.wepKeys[0]="\""+pass+"\"";
conf.wepTxKeyIndex=0;
conf.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
}
break;
}
}
}
wifiManager.addNetwork(conf);
List<WifiConfiguration> list=wifiManager.getConfiguredNetworks();
for(WifiConfiguration i: list){
if(i.SSID!=null && i.SSID.equals("\""+nameWifi+"\"")){
wifiManager.disconnect();
showWaiting();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
if(networkInfo.isConnected()){
dismissWaiting();
}else{
AlertDialog.Builder alert=new AlertDialog.Builder(MainActivity.this);
alert.setTitle("Wrong Password")
.setMessage("Please try again")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.create().show();
}
}
}
break;
}
}
}
i have 2 Activities (MainActivity and ShareWifi), i create Sharewifi with purpose: users input wifi SSID and password then press Enter, both of them will send to MainActivity--> disable current wifi and reconnect with new password but it still uses old password to reconnect. I write this code follow this link : How do I connect to a specific Wi-Fi network in Android programmatically?
Please help me to resolve this problem. Thank you very much.
Resolved: add saveConfiguration and it works
wifiManager.addNetwork(conf);
wifiManager.saveConfiguration();

No internet over BES connection - BlackBerry

My BlackBerry App is unable to connect to the internet through BES. It successfully connects via Wifi, BIS, GPRS etc but does not detect internet connection over BES. I have checked all the settings and the browser is connecting to the internet but not the App. My connection method is as follows:
static String connectionParameters = "";
public static String checkInternetConnection(){
//String connectionParameters = "";
if(CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE)
{
connectionParameters=null;
}
else
{
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
// Connected to a WiFi access point
connectionParameters = ";interface=wifi";
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null
&& (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage and a WAP 2.0 service book record
connectionParameters = ";deviceside=true;ConnectionUID="
+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
connectionParameters = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage but no WAP 2.0 service book record
connectionParameters = ";deviceside=true";
}
}
}
return connectionParameters;
}
private static ServiceRecord getWAP2ServiceRecord() {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.getRecords();
for(int i = 0; i < records.length; i++) {
String cid = records[i].getCid().toLowerCase();
String uid = records[i].getUid().toLowerCase();
if (cid.indexOf("wptcp") != -1 &&
uid.indexOf("wifi") == -1 &&
uid.indexOf("mms") == -1) {
return records[i];
}
}
return null;
}
Please help!
EDIT: The App is trying to access the server which is available on the intranet. The App fails to access internet (google web service) and intranet (local server) over BES. Can anyone comment?
first you check whether you have BES sufficient coverage and this you get when you have BES plan.

Check wifi condition in Blackberry application

I have developed an application for blackberry devices. The application is working fine if it uses internet via data service provider.
I have BB 9550 and I want to use my application using wifi. I tried a lot but I cant get proper answer to check wifi condition.
How we can differentiate to run our application for wifi or data service provider?
For checking wifi is connected or not the following method will help you.
public static boolean isWifiConnected()
{
try
{
if (RadioInfo.getSignalLevel(RadioInfo.WAF_WLAN) != RadioInfo.LEVEL_NO_COVERAGE)
{
return true;
}
}
catch(Exception e)
{
System.out.println("Exception during get WiFi status");
}
return false;
}
if wifi is not connected the following methods will help to add data service.
public static String getConnParam(){
String connectionParameters = "";
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
// Connected to a WiFi access point
connectionParameters = ";interface=wifi";
} else {
int coverageStatus = CoverageInfo.getCoverageStatus();
ServiceRecord record = getWAP2ServiceRecord();
if (record != null
&& (coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage and a WAP 2.0 service book record
connectionParameters = ";deviceside=true;ConnectionUID="
+ record.getUid();
} else if ((coverageStatus & CoverageInfo.COVERAGE_MDS) ==
CoverageInfo.COVERAGE_MDS) {
// Have an MDS service book and network coverage
connectionParameters = ";deviceside=false";
} else if ((coverageStatus & CoverageInfo.COVERAGE_DIRECT) ==
CoverageInfo.COVERAGE_DIRECT) {
// Have network coverage but no WAP 2.0 service book record
connectionParameters = ";deviceside=true";
}
}
return connectionParameters;
}
private static ServiceRecord getWAP2ServiceRecord() {
ServiceBook sb = ServiceBook.getSB();
ServiceRecord[] records = sb.getRecords();
for(int i = 0; i < records.length; i++) {
String cid = records[i].getCid().toLowerCase();
String uid = records[i].getUid().toLowerCase();
if (cid.indexOf("wptcp") != -1 &&
uid.indexOf("wifi") == -1 &&
uid.indexOf("mms") == -1) {
return records[i];
}
}
return null;
}
Example to use above methods.
String connParams=(isWifiConnected())?";interface=wifi":getConnParam();
Hope This will help you
try this:
private static String getParameters() {
if (GetWiFiCoverageStatus()) {
return ";deviceside=true;interface=wifi";
}
else {
return yourParametersForEdge
}
}
private static boolean GetWiFiCoverageStatus() {
if((WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)) {
return true;
}
else
return false;
}
And when you need to connect, you'll have to add the parameters to the URL:
yourUrl = yourUrl + getParameters();

APN is not specified?

iam creating httpConnection ,but when run the application it gives following exception ?
java.io.IOException
APN is not specified ?
I think the See the Developer Knowledge Base article: link can solve your problem
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is_-_Different_ways_to_make_an_HTTP_or_socket_connection.html?nodeid=826935&vernum=0
also see this sample code
private static String getConnectionString(){
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;
}
More to the point,
http://supportforums.blackberry.com/t5/Java-Development/How-to-get-APN-Settings/td-p/1704995
It is not completely possible to put the APN settings in your url eg. there is no way to get the username and password.

Resources