Import the Cognalys library to your workspace.


Create an android app in your workspace.


Right click on the project and add the cognalys libary to your app and click apply and ok.


Then open your Manifest file of your project.


project_name->AndroidManifest.xml



Manifest changes


open AndroidManifest.xml file

add below permissions to your app




 

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />

 


And declare this activity in your project


 

<activity
android:name="com.matesnetwork.Cognalys.VerifyMobile"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
</activity

 

Create a Broadcast reciever class and add to your manifes


(NB: don't forget to add intent filter)




   

<receiver android:name="com.matesnetwork.cogdemov2.CognalysVerification" >
<intent-filter>
<action android:name="com.matesnetwork.cognalys" />
</intent-filter> 

   



open your main class


project_name->packages->your_activity




add this code to your verify mobile button click or any other listener



   

Intent in = new Intent(MainActivity.this, VerifyMobile.class);
in.putExtra("app_id", "YOUR_APP_ID_HERE");
in.putExtra("access_token","YOUR_ACCESS_TOKEN_HERE");
in.putExtra("mobile", "mobile number for verification");	

startActivityForResult(in,VerifyMobile.REQUEST_CODE); 

  

 

(Note : replace YOUR_APP_ID_HERE , YOUR_ACCESS_TOKEN_HERE by yours ( Tutorial ) 






Implement the override method to you activity


 

@Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
// TODO Auto-generated method stub
super.onActivityResult(arg0, arg1, arg2);

}
}

 


add this code to the override method



 

if (arg0 == VerifyMobile.REQUEST_CODE) {
String message = arg2.getStringExtra("message");
int result=arg2.getIntExtra("result", 0);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT).show();
} 

 user will get the message in “message” field

and alse get the result codes in “result” field




result codes


101 = "MISSING CREDENTIALS";

102 = "MISSING REQUIRED VALUES";

103 = "MISSING PROPER NUMBER";

104 = "VERIFICATION SUCCESS";

105 = "NUMBER IS NOT CORRECT";

106 = "MOBILE NUMBER VERIFICATION CANCELED";

107 = "NETWORK ERROR CANNOT BE VERIFIED";

108 = "MOBILE NUMBER VERIFICATION FAILED, NO INTERNET";



Create a Class and extends the interface BroadcastReceiver


 

public class CognalysVerification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String mobile = intent.getStringExtra("mobilenumber");
String app_user_id = intent.getStringExtra("app_user_id");
Toast.makeText(context, mobile, Toast.LENGTH_SHORT)
.show();
Toast.makeText(context, app_user_id, Toast.LENGTH_SHORT)
.show();
}

}

 


in this onReceive method user will get the verified mobile number and app_user_id

Files


MainActivity.java



   

package com.matesnetwork.cogdemov2;

import com.matesnetwork.Cognalys.VerifyMobile;

import android.support.v7.app.ActionBarActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {
Button test;
EditText mobilenum;
EditText countrycode;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
test = (Button) findViewById(R.id.test);
mobilenum = (EditText) findViewById(R.id.editText1);
countrycode = (EditText) findViewById(R.id.editText2);
countrycode.setText(VerifyMobile
.getCountryCode(getApplicationContext()));
test.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String mobile = countrycode.getText().toString()
+ mobilenum.getText().toString();
Intent in = new Intent(MainActivity.this, VerifyMobile.class);

in.putExtra("app_id", "YOUR_APP_ID_HERE");
in.putExtra("access_token",
"YOUR_ACCESS_TOKEN_HERE");
in.putExtra("mobile", mobile);
startActivityForResult(in, VerifyMobile.REQUEST_CODE);
}
});
}

@Override
protected void onActivityResult(int arg0, int arg1, Intent arg2) {
// TODO Auto-generated method stub
super.onActivityResult(arg0, arg1, arg2);

if (arg0 == VerifyMobile.REQUEST_CODE) {
String message = arg2.getStringExtra("message");
int result = arg2.getIntExtra("result", 0);

Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT)
.show();
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_SHORT)
.show();

}
}

} 

 


(Note : replace YOUR_APP_ID_HERE , YOUR_ACCESS_TOKEN_HERE by yours ( Tutorial ) 


 




 CognalysVerification.java (broadcast receiver)




  

package com.matesnetwork.cogdemov2;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class CognalysVerification extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String mobile = intent.getStringExtra("mobilenumber");
String app_user_id = intent.getStringExtra("app_user_id");
Toast.makeText(context, mobile, Toast.LENGTH_SHORT)
.show();
Toast.makeText(context, app_user_id, Toast.LENGTH_SHORT)
.show();
}

}