Thursday, 15 December 2016

how-to-create-signed-apk-file-using-cordova-command-line-interface

how to create signed APK file using cordova command line interface:



Step 1:

D:\projects\Phonegap\Example> cordova plugin rm org.apache.cordova.console --save
add the --save so that it removes the plugin from the config.xml file.

Step 2:

To generate a release build for Android, we first need to make a small change to the AndroidManifest.xml file found in platforms/android. Edit the file and change the line:
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
and change android:debuggable to "false":
<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
As of cordova 6.2.0 remove the android:debuggable tag completely. Here is the explanation from cordova:
Explanation for issues of type "HardcodedDebugMode": It's best to leave out the android:debuggable attribute from the manifest. If you do, then the tools will automatically insert android:debuggable=true when building an APK to debug on an emulator or device. And when you perform a release build, such as Exporting APK, it will automatically set it to false.
If on the other hand you specify a specific value in the manifest file, then the tools will always use it. This can lead to accidentally publishing your app with debug information.

Step 3:

Now we can tell cordova to generate our release build:
D:\projects\Phonegap\Example> cordova build --release android
Then, we can find our unsigned APK file in platforms/android/ant-build. In our example, the file was platforms/android/ant-build/Example-release-unsigned.apk

Step 4:

Note : We have our keystore 'keystoreNAME-mobileapps.keystore' in this Git Repo, if you want to create another, please proceed with the following steps.

Key Generation:

Syntax:

keytool -genkey -v -keystore <keystoreName>.keystore -alias <Keystore AliasName> -keyalg <Key algorithm> -keysize <Key size> -validity <Key Validity in Days>

Egs:

keytool -genkey -v -keystore NAME-mobileapps.keystore -alias NAMEmobileapps -keyalg RSA -keysize 2048 -validity 10000


keystore password? : xxxxxxx
What is your first and last name? :  xxxxxx
What is the name of your organizational unit? :  xxxxxxxx
What is the name of your organization? :  xxxxxxxxx
What is the name of your City or Locality? :  xxxxxxx
What is the name of your State or Province? :  xxxxx
What is the two-letter country code for this unit? :  xxx
Then the Key store has been generated with name as NAME-mobileapps.keystore

Step 5:

Place the generated keystore in
old version cordova D:\projects\Phonegap\Example\platforms\android\ant-build
New version cordova D:\projects\Phonegap\Example\platforms\android\build\outputs\apk
To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:

Syntax:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <keystorename <Unsigned APK file> <Keystore Alias name>

Egs:

D:\projects\Phonegap\Example\platforms\android\ant-build> jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore Example-release-unsigned.apk xxxxxmobileapps
OR D:\projects\Phonegap\Example\platforms\android\build\outputs\apk> jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore Example-release-unsigned.apk xxxxxmobileapps
Enter KeyPhrase as 'xxxxxxxx'
This signs the apk in place.

Step 6:

Finally, we need to run the zip align tool to optimize the APK:
D:\projects\Phonegap\Example\platforms\android\ant-build> zipalign -v 4 Example-release-unsigned.apk Example.apk 
OR
D:\projects\Phonegap\Example\platforms\android\ant-build> C:\Phonegap\adt-bundle-windows-x86_64-20140624\sdk\build-tools\android-4.4W\zipalign -v 4 Example-release-unsigned.apk Example.apk
OR
D:\projects\Phonegap\Example\platforms\android\build\outputs\apk> C:\Phonegap\adt-bundle-windows-x86_64-20140624\sdk\build-tools\android-4.4W\zipalign -v 4 Example-release-unsigned.apk Example.apk
Now we have our final release binary called example.apk and we can release this on the Google Play Store.





Step by Step Tips   :

(1)tell cordova to generate our release build:

cordova build --release

(2)Key Generation:

keytool -genkey -v -keystore NAME-mobileapps.keystore -alias NAME-mobileapps -keyalg RSA -keysize 2048 -validity 10000

(note: NAME-mobileapps.keystore is keystore name and NAME-mobileapps is alias name and kyesize is 20148 and validity is 10000)

OR TRY:

cordova run android --release -- --keystore=NAME-mobileapps.keystore --storePassword=om@1234 --alias=NAME-mobileapps.keystore --password=om@1234


(3)Place the generated keystore in

old version cordova D:\projects\Phonegap\Example\platforms\android\ant-build

New version cordova D:\projects\Phonegap\Example\platforms\android\build\outputs\apk

(4)
D:\projects\Phonegap\Example\platforms\android\build\outputs\apk>jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore android-release-unsigned.apk NAME-mobileapps

or

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore android-release-unsigned.apk NAME-mobileapps
and

Enter KeyPhrase as 'xxxxxxxx'

here keyPhrase is your password of keystore.
(

Note:
Check your keystore alias name once. Some times keystore alias name is different from keytool alias name then it gives the  error...So check it alias names once)



(5)zipalign -v 4 Example-release-unsigned.apk Example.apk  (Note: first set path="D:\om\Android development detials\android-sdk-windows\build-tools\24.0.0")



zipalign -v 4 android-release-unsigned.apk  Example.apk

EXAMPLE:

D:\phpnotes\platforms\android\build\outputs\apk>set path="D:\om\Android developm
ent detials\android-sdk-windows\build-tools\24.0.0"

D:\phpnotes\platforms\android\build\outputs\apk>zipalign -v 4 android-release-un
signed.apk omsir.apk

Saturday, 10 December 2016

Android – WebViewClient example:

Android –  WebViewClient  example:
 What is WebViewClient and what is it’s usage?
When the user clicks a link from a web page in your WebView, the default behavior is for Android to launch an application that handles URLs. Usually, the default web browser opens and loads the destination URL. However, you can override this behavior for your WebView, so links open within your WebView. You can then allow the user to navigate backward and forward through their web page history that’s maintained by your WebView.
To open links clicked by the user, simply provide a WebViewClient for your WebView, using setWebViewClient().
Demo of creating an application to open any URL inside the application and clicking on any link from that URl
should not open Native browser but that URL should open in the same screen.


(1)write    code  for  MainAcitvity.java  file  :
package ommaurya.om.com.webviewclient;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/*
 * Demo of creating an application to open any URL inside the application and clicking on any link from that URl
should not open Native browser but  that URL should open in the same screen.
 */
public class MainActivity extends Activity {
   
/** Called when the activity is first created. */

   
WebView web;

   
@Override
   
public void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);

       
web = (WebView) findViewById(R.id.webview01);
       
web.setWebViewClient(new myWebClient());
       
web.getSettings().setJavaScriptEnabled(true);
       
web.loadUrl("http://www.vissicomp.in");
    }

   
public class myWebClient extends WebViewClient
    {
       
@Override
       
public void onPageStarted(WebView view, String url, Bitmap favicon) {
            
// TODO Auto-generated method stub
           
super.onPageStarted(view, url, favicon);
        }

       
@Override
       
public boolean shouldOverrideUrlLoading(WebView view, String url) {
           
// TODO Auto-generated method stub

            
view.loadUrl(url);
           
return true;

        }
    }

   
// To handle "Back" key press event for WebView to go back to previous screen.
   
@Override
   
public boolean onKeyDown(int keyCode, KeyEvent event)
    {
       
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
           
web.goBack();
           
return true;
        }
       
return super.onKeyDown(keyCode, event);
    }
}



(2)write  code for  activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

    android:layout_height="match_parent" android:fitsSystemWindows="true"

    tools:context=".MainActivity">



    <android.support.design.widget.AppBarLayout android:layout_height="wrap_content"

        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">



        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"

            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"

            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />



    </android.support.design.widget.AppBarLayout>



    <include layout="@layout/content_main" />



    <android.support.design.widget.FloatingActionButton android:id="@+id/fab"

        android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"

        android:src="@android:drawable/ic_dialog_email" />



</android.support.design.widget.CoordinatorLayout>

(3)Write   code for conent_main.xml file:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin"

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

    tools:showIn="@layout/activity_main" tools:context=".MainActivity">



    <TextView android:text="Hello World!" android:layout_width="wrap_content"

        android:layout_height="wrap_content" />







    <WebView

        android:id="@+id/webview01"

        android:layout_height="wrap_content"

        android:layout_width="fill_parent"

        android:layout_weight="1">

    </WebView>



</RelativeLayout>


 output:





Wednesday, 12 October 2016

GRID LAYOUT

GRID LAYOUT EXAMPLE  USING  TABLE  FOR MOBILE APPS:


<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 
<div class="container">
 
  <div class="table-responsive">
  <table class="table">
    <thead>
      <tr>
     
        <th><img src="1.png" height=60 width=60></th>
        <th><img src="1.png" height=60 width=60></th>
        <th><img src="1.png" height=60 width=60></th>
        <th><img src="1.png" height=60 width=60></th>
       
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><img src="1.png" height=60 width=60></td>
        <td><img src="1.png" height=60 width=60></td>
        <td><img src="1.png" height=60 width=60></td>
        <td><img src="1.png" height=60 width=60></td>
       
      </tr>
    </tbody>
  </table>
  </div>
</div>

</body>
</html>

Output:



Wednesday, 5 October 2016

Android Workshop by Om Sir


Saturday, 3 September 2016

SideBar example using html and javascript for mobile application

(1)write following code  and save as  sidebar.html   file:

<!DOCTYPE html>
<html>
<style>
body {
    font-family: "Lato", sans-serif;
    transition: background-color .5s;
}

.sidenav {
    height: 100%;
    width: 0;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #111;
    overflow-x: hidden;
    transition: 0.5s;
    padding-top: 60px;
}

.sidenav a {
    padding: 8px 8px 8px 32px;
    text-decoration: none;
    font-size: 25px;
    color: #818181;
    display: block;
    transition: 0.3s
}

.sidenav a:hover, .offcanvas a:focus{
    color: #f1f1f1;
}

.sidenav .closebtn {
    position: absolute;
    top: 0;
    right: 25px;
    font-size: 36px;
    margin-left: 50px;
}

#main {
    transition: margin-left .5s;
    padding: 16px;
}

@media screen and (max-height: 450px) {
  .sidenav {padding-top: 15px;}
  .sidenav a {font-size: 18px;}
}
</style>
<body>

<div id="mySidenav" class="sidenav">
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
  <a href="#">About</a>
  <a href="#">Services</a>
  <a href="#">Clients</a>
  <a href="#">Contact</a>
</div>

<div id="main">
  <h2>Sidenav Push Example</h2>
  <p>Click on the element below to open the side navigation menu, and push this content to the right. Notice that we add a black see-through background-color to body when the sidenav is opened.</p>
  <span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; open</span>
</div>

<script>
function openNav() {
    document.getElementById("mySidenav").style.width = "250px";
    document.getElementById("main").style.marginLeft = "250px";
    document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
}

function closeNav() {
    document.getElementById("mySidenav").style.width = "0";
    document.getElementById("main").style.marginLeft= "0";
    document.body.style.backgroundColor = "white";
}
</script>
   
</body>
</html>

output:


Tuesday, 23 August 2016

SIMPLE LOGIN APPS EXAMPLE WITH PHP WEBSRVICE


Write code for   “loginpost .php”    file  for  webservice  :

<?php

$username = $_POST['username'];
$password = $_POST['password'];

if($username=="om" && $password=="admin")
{
echo "true";
}
else
{
echo " false";
}

?>


and  upload  it to the server  and copy link:

http://funmoviemasti.com/om/loginpost.php



(1)Write code for   MainActivity.java   login:
package com.guru.login;

import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

   
// CONNECTION_TIMEOUT and READ_TIMEOUT are in milliseconds

   
public static final int CONNECTION_TIMEOUT=10000;
   
public static final int READ_TIMEOUT=15000;
   
private EditText etEmail;
   
private EditText etPassword;

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);

       
// Get Reference to variables
       
etEmail = (EditText) findViewById(R.id.email);
       
etPassword = (EditText) findViewById(R.id.password);

    }

   
// Triggers when LOGIN Button clicked
   
public void checkLogin(View arg0) {

       
// Get text from email and passord field
       
final String email = etEmail.getText().toString();
       
final String password = etPassword.getText().toString();

           
// Initialize  AsyncLogin() class with email and password
           
new AsyncLogin().execute(email,password);

    }

   
private class AsyncLogin extends AsyncTask<String, String, String>
    {
        ProgressDialog
pdLoading = new ProgressDialog(MainActivity.this);
        HttpURLConnection
conn;
        URL
url = null;

       
@Override
       
protected void onPreExecute() {
           
super.onPreExecute();

           
//this method will be running on UI thread
           
pdLoading.setMessage("\tLoading...");
           
pdLoading.setCancelable(false);
           
pdLoading.show();

        }
       
@Override
       
protected String doInBackground(String... params) {
           
try {

               
// Enter URL address where your php file resides
               
url = new URL("http://funmoviemasti.com/om/loginpost.php");

            }
catch (MalformedURLException e) {
               
// TODO Auto-generated catch block
               
e.printStackTrace();
               
return "exception";
            }
           
try {
                
// Setup HttpURLConnection class to send and receive data from php and mysql
               
conn = (HttpURLConnection)url.openConnection();
               
conn.setReadTimeout(READ_TIMEOUT);
               
conn.setConnectTimeout(CONNECTION_TIMEOUT);
               
conn.setRequestMethod("POST");

               
// setDoInput and setDoOutput method depict handling of both send and receive
               
conn.setDoInput(true);
               
conn.setDoOutput(true);

               
// Append parameters to URL
               
Uri.Builder builder = new Uri.Builder()
                        .appendQueryParameter(
"username", params[0])
                        .appendQueryParameter(
"password", params[1]);
                String query = builder.build().getEncodedQuery();

               
// Open connection for sending data
               
OutputStream os = conn.getOutputStream();
                BufferedWriter writer =
new BufferedWriter(
                       
new OutputStreamWriter(os, "UTF-8"));
                writer.write(query);
                writer.flush();
                writer.close();
                os.close();
               
conn.connect();

            }
catch (IOException e1) {
               
// TODO Auto-generated catch block
                
e1.printStackTrace();
               
return "exception";
            }

           
try {

               
int response_code = conn.getResponseCode();

               
// Check if successful connection made
               
if (response_code == HttpURLConnection.HTTP_OK) {

                   
// Read data sent from server
                   
InputStream input = conn.getInputStream();
                    BufferedReader reader =
new BufferedReader(new InputStreamReader(input));
                    StringBuilder result =
new StringBuilder();
                    String line;

                   
while ((line = reader.readLine()) != null) {
                        result.append(line);
                    }

                   
// Pass data to onPostExecute method
                   
return(result.toString());

                }
else{

                   
return("unsuccessful");
                }

            }
catch (IOException e) {
                e.printStackTrace();
               
return "exception";
            }
finally {
               
conn.disconnect();
            }


        }

       
@Override
       
protected void onPostExecute(String result) {

           
//this method will be running on UI thread

           
pdLoading.dismiss();

            
if(result.equalsIgnoreCase("true"))
            {
               
/* Here launching another activity when login successful. If you persist login state
                use sharedPreferences of Android. and logout button to clear sharedPreferences.
                 */

               
Intent intent = new Intent(MainActivity.this,SuccessActivity.class);
                startActivity(intent);
                MainActivity.
this.finish();

            }
else if (result.equalsIgnoreCase("false")){

                
// If username and password does not match display a error message
               
Toast.makeText(MainActivity.this, "Invalid email or password", Toast.LENGTH_LONG).show();

            }
else if (result.equalsIgnoreCase("exception") || result.equalsIgnoreCase("unsuccessful")) {

                Toast.makeText(MainActivity.
this, "OOPs! Something went wrong. Connection Problem.", Toast.LENGTH_LONG).show();

            }
        }

    }
}

(2)write  code  for activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">



    <EditText

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:inputType="textEmailAddress"

        android:ems="10"

        android:id="@+id/email"

        android:layout_alignParentTop="true"

        android:layout_alignParentLeft="true"

        android:layout_alignParentStart="true"

        android:hint="Email"

        android:layout_marginTop="10dp"/>



    <EditText

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:inputType="textPassword"

        android:ems="10"

        android:id="@+id/password"

        android:layout_below="@+id/email"

        android:hint="Password"

        android:layout_marginTop="10dp"/>



    <Button

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:text="LOGIN"

        android:id="@+id/button"

        android:layout_below="@+id/password"

        android:layout_marginTop="10dp"

        android:onClick="checkLogin"/>



</RelativeLayout>

(3)write code for   SuccessActivity.java file:
package com.guru.login;



import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;



public class SuccessActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_success);

    }

}

(4)write   code for  activity_success.xml file:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    android:paddingBottom="@dimen/activity_vertical_margin">



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceLarge"

        android:text="WELCOME"

        android:id="@+id/textView"

        android:layout_alignParentTop="true"

        android:layout_centerHorizontal="true"

        android:layout_marginTop="62dp" />



    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textAppearance="?android:attr/textAppearanceMedium"

        android:text="Successfully LoggedIn"

        android:id="@+id/textView2"

        android:layout_marginTop="46dp"

        android:layout_below="@+id/textView"

        android:layout_centerHorizontal="true" />



</RelativeLayout>


 OUTPUT:




Recent Posts

Powered by Blogger.

Pages

About Me

My Photo
B.E.(COMPUTER ENGINEER) PHP Web developer & Provide Training for Web Development , Digital Marketing ,Android Mobile Apps Development

 

© 2013 ANDROID TRAINING IN MUMBAI BY OM SIR. All rights resevered. Designed by Templateism

Back To Top