Search This Blog

Monday 25 November 2013

How to check the INTERNET & GPS connection in Android


----------------------------------------------------------------------------------------------------
ConnectivityManager only give information of the connection (WiFi, mobile, WiMax, etc) and if it is connected or not.

public boolean isGPSEnabled(){

LocationManager lm;
boolean GPS_Status =false;
boolean gps_enabled = false;
String title,message="";
try{
lm = (LocationManager)this.getSystemService(LOCATION_SERVICE);
gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
}catch(Exception e){
e.printStackTrace();
}

if(gps_enabled){
GPS_Status = true;
title="GPS ENABLED";
message ="GPS is  enabled.";
GPSChecker.showAlertDialog(this, title, message);
}else{
title="GPS Disabled";
message ="GPS is not enabled.Please TurnOn the GPS";
GPSChecker.showAlertDialog(this, title, message);
}
return GPS_Status;
}

----------------------------------------------------------------------------------------------------


/*
* This method does check-  ARE WE CONNECTED TO THE NET
*/
public final boolean isInternetOn()
{
String title,message="";
boolean connected = false;
ConnectivityManager connec = (ConnectivityManager)
   getSystemService(Context.CONNECTIVITY_SERVICE);

 if (connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
 connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED ){

 // MESSAGE TO SCREEN FOR TESTING (IF REQ)
 title="Internet ENABLED";
 message ="Internet is  enabled.";
 GPSChecker.showAlertDialog(this, title, message);
 connected = true;

 }else if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED
 ||  connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED  ){

 connected =  false;
 title="Internet DISABLED";
 message ="Internet is  disabled.";
 GPSChecker.showAlertDialog(this, title, message);
 }
 return connected;
}


----------------------------------------------------------------------------------------------------

Tuesday 19 November 2013

Configuring Liferay 6.1 CE GA3 on JBoss-7.1.1 -ee-ga3

Incase you are going to setup -" liferay-portal-jboss-6.1.30-ee-ga3" , probably this blog can be of some help..as hereby i put aal my findings & steps i followed to successfully configure the same..



Few of the LINKS Followed ::


1>> Starting Server :
 Start the extracted server >> now goto  the following path -”D:\PROJECTS\Scali\liferay-JBOSS_HOME-ga3\jboss-7.1.1\bin” and double click the standalone.bat [for Windows] or you can start the same .bat file from cmd as well by going to the respective path .It will start the Server @ localhost:8080 by default.
If Its Not Started --check for the respective Error @console.
Note: Check your jdk version .Incase you are using Jboss 7.x.x its advised to use jdk7 and like wise.


2>>Incase of EE :
now you can see the deploy folder @ following path - “D:\myWorkspace\liferay-JBOSS_HOME-ga3\”  ,wch wasnt thr untill you’ll start the server atleast once. Since using an EE , need to attach a  license key [wch you can register @ liferay.com and get your trial/etc license key] , now Paste your Licence- xml file here---it will be auto deployed.Refresh the portal (default localhost:8080) --you’ll see the Basic Config page. Config ur Database here and proceed.


3>> Configuring MYSQL:
Incase you wanna configure -’MySQL’ …. copy the “mysql-connector-java-3.0.9.jar” @ following location of ur Jboss_Home-
D:\PROJECTS\Scali\liferay-JBOSS_HOME-ga3\jboss-7.1.1\modules\com\liferay\portal\main
also you need to update the module.xml present @ same loc --communicating to jboss tht u’re interested in using this resource [mysql jar ]. RESTART your Server now..


Issues Faced :
  • 08:56:20,986 INFO  [stdout] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1) 08:56:20,982 WARN  [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolTh
read-#1][BasicResourcePool:1841] com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@285dec -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying
to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (3). Last acquisition attempt exception:
08:56:21,015 INFO  [stdout] (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1) java.sql.SQLException: Unable to connect to any hosts due to exception: java
.lang.ArrayIndexOutOfBoundsException: 40
i was using mysql jar -- ’mysql-connector-java-3.0.9.jar’ ...later used a higher version jar as this one was to Old ..so i used mysql-connector-java-3.0.17-ga-bin.jar  [Advised to use any jar of versdion >=3.0.15 ]


Issues Faced :   Another Mistake i did while Configuring mysql was to replace the hsql.jar entry with the mysql-connector-java..jar  in the module.xml.  Dont Do that as the hsql.jar is still required while deploying the ROOT.war portlet (default portlet). See below extract from module.xml for better understanding..



Don’t replace the resource-root entry of - hsql.jar with that of ‘mysql-connector-java.x.x.jar ...Instead Add a new resource-root entry ….
<resources>
<resource-root path="mysql-connector-java-3.0.17-ga-bin.jar" />      [NEW ENTRY]
      <resource-root path="hsql.jar" />
       <resource-root path="jtds.jar" />
       
       <resource-root path="portal-service.jar" />
       <resource-root path="portlet.jar" />
       <resource-root path="postgresql.jar" />
   </resources>


4>> Deploying a Portlet :::
InCase of DIRECT- DEPLOYMENT ::
You can drop your portlet war file directly @ following loc --
“D:\PROJECTS\Scali\liferay_JBoss_Home-ce-ga3\deploy“..If the server is started it’ll Autodeploy.  


[Also to Mention ,Many a blogs advocate creating a blank file along with your war file at this location say: your war file is ABC.war the create a file named ABC.war.dodeploy and drop @
{D:\Workspace\liferay-JBOSS_HOME-ga3\jboss-7.1.1\standalone\deployments} loc ,BUT incase you try … Its will give the following exceptions @ console..


:26:13,888 WARN  [org.jboss.as.ee] (MSC service thread 1-1) JBAS011006: Not installing optional component com.liferay.taglib.ui.AssetCategoriesSummaryTag due to exception : java.lang.ClassNotFoundException: com.liferay.taglib.ui.AssetCategoriesSummaryTag from [Module "deployment.ABC-portlet-6.1.1.1.war:main" from Service Module Loader]
     at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
     at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
     at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
     at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
     at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0]
     at java.lang.Class.forName(Class.java:264) [rt.jar:1.7.0]
     at org.jboss.as.server.deployment.reflect.DeploymentClassIndex.classIndex(DeploymentClassIndex.java:54) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
     at org.jboss.as.ee.component.deployers.EEModuleConfigurationProcessor.deploy(EEModuleConfigurationProcessor.java:79)
     at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
     at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
     at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0]
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0]
     at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0]


:26:13,958 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /ABC-portlet-6.1.1.1
:26:14,025 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "ABC-portlet-6.1.1.1.war"



InCase of ANT- DEPLOYMENT ::
Also, if you try to deploy using ANT (if configured properly) , you may get the same series of exceptions .
To Overcome the same -- add the following to your build.{username}.properties
--------------------------------------------------------------------------------------------------------
#
# Specify the paths to an unzipped JBoss bundle.
#


app.server.type=jboss
app.server.parent.dir=D:/PROJECTS/my_Project_name/liferay_JBoss_Home-ce-ga3
app.server.jboss.dir=${app.server.parent.dir}/jboss-7.1.1
app.server.jboss.deploy.dir=${app.server.parent.dir}/deploy
app.server.jboss.lib.global.dir=${app.server.jboss.dir}/modules/com/liferay/portal/main
app.server.jboss.portal.dir=${app.server.jboss.dir}/standalone/deployments/ROOT.war
javac.compiler = modern


auto.deploy.dir=${app.server.jboss.deploy.dir}
--------------------------------------------------------------------------------------------------------
5>> Configuring Plugins sdk :::  Here's very nice link you can refer for configuring Plugins-Sdk (In case you haven't done it uptill now)
Refer : http://techconf.wordpress.com/2012/12/30/develop-liferay-portlet-plugin-project-without-liferay-ide-support-in-eclipse-on-jboss-server/

Monday 11 November 2013

Erros in building service - Error occurred during initialization of VM , Could not reserve enough space for object heap


#### ERROR --

[Console output redirected to file:D:\MTSTravel\.metadata\.plugins\com.liferay.ide.eclipse.sdk\sdk.log]
Buildfile: D:\xxxxxx\plugins-sdk-6.1.1\portlets\mts-portlet\build.xml
build-service:
     [java] Java Result: 1
     [echo] Error occurred during initialization of VM
     [echo] Could not reserve enough space for object heap
     [echo] Error: Could not create the Java Virtual Machine.
     [echo] Error: A fatal exception has occurred. Program will exit.

BUILD FAILED
D:\xxxxxx\plugins-sdk-6.1.1\build-common-plugin.xml:207: Service Builder generated exceptions.
Total time: 6 seconds




#### SOLUTION --

I faced this ExceptionThis is what resolved the issue for me , thus sharing hereby expecting it could be of some help to you as well...

SDK ,change the file build-common-plugin.xml from
<jvmarg value="-Xms512m" />
<jvmarg value="-Xmx1024m" />
to
<jvmarg value="-Xms128m" />
<jvmarg value="-Xmx512m" />