Tuesday, 10 July 2018

android firebase tutorial -- authentication malayalam

ആദ്യം   android studio യിൽ  പോയ് firebase ടൂൾസിൽ  click ചെയ്യണം
പിന്നീട്   gmail (google) account sign ചെയ്യാൻ  അതിൽ  option കാണും

1.connect to firebase
നിങ്ങളുടെ  രാജ്യം  select ചെയ്യാൻ  അതിൽ  option കാണും

2.add firebase authentication your app
Accept and changes click ചെയ്യുക

3.https://console.firebase.google.com/
ചെന്ന്
https://console.firebase.google.com/project/--yourprojectname--/authentication/providers
email/password enable ചെയ്യുക

ഇനി  പ്രോഗ്രാമിലോട്ടു  വരാം

4.private FirebaseAuth mAuth;
ഇത്  class ൽ global variable ആക്കി  set ചെയ്യുക

5.mAuth = FirebaseAuth.getInstance()
ഇത്  oncreate bundle constructor ഫങ്ക്ഷനിൽ  കൊടുക്കുക

6.
@Override
public void onStart() {
    super.onStart();
    // Check if user is signed in (non-null) and update UI accordingly.
    FirebaseUser currentUser = mAuth.getCurrentUser();
    updateUI(currentUser);
}

ഇത്  ഒരു  onStart() overide function നീൽ  
 FirebaseUser currentUser = mAuth.getCurrentUser();paste ചെയ്യുക

ഈ  current user വെച്ച്  കൊണ്ട്  user ഉണ്ടോ  ഇല്ലയോ  എന്ന്  ചെക്ക്  ചെയ്യാൻ  കഴിയും
if(currentUser ==nul)
{
current user ഇല്ല  എങ്കിൽ  ഇത്  ചെയ്യുക
}

7.user registration email and  password വെച്ച്  ചെയ്യാൻ 
ഇനി  already register ചെയ്തിട്ടുണ്ടെൽ  step 8 ഇലോട്ടു  പോവുക 
ഇത്  ഒരു  button click ചെയ്താൽ  ചെയ്യേണ്ടതാണ്  അതിൽ  ഒരു  method കൊടുക്കുക  register__User(String displayname,String username,String password);


mAuth.createUserWithEmailAndPassword(email, password)
        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                   // Log.d(TAG, "createUserWithEmail:success");
                 //   FirebaseUser user = mAuth.getCurrentUser();
                  //  updateUI(user);
sign in ആയാൽ  succes  പേജ്  ഇലോട്ടു  പോവുക  eg:
ഇവിടെ  user account page ഇലോട്ടു  direct ചെയ്യാം  
                } else {
                    // If sign in fails, display a message to the user.
                  //  Log.w(TAG, "createUserWithEmail:failure", task.getException());
                 //   Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
                   //         Toast.LENGTH_SHORT).show();
                 //   updateUI(null);
. എന്തോ  പ്രശനം  ഉണ്ട് 
അത്  കൊണ്ട്  home register page ഇലോട്ടു  തന്നെ  redirect ചെയ്യാം  
                }

                // ...
            }
        });

8.sign in ചെയ്യാൻ
mAuth.signInWithEmailAndPassword(email, password)
        .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (task.isSuccessful()) {
                    // Sign in success, update UI with the signed-in user's information
                   // Log.d(TAG, "signInWithEmail:success");
                   // FirebaseUser user = mAuth.getCurrentUser();
                  //  updateUI(user);
                 user succes ആയി  sign in ചെയ്തിരിക്കുന്നു  ഇനി  അടുത്ത  പേജിലോട്                     പോകാം 
                } else {
                    // If sign in fails, display a message to the user.
                  //  Log.w(TAG, "signInWithEmail:failure", task.getException());
                   // Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
                      //      Toast.LENGTH_SHORT).show();
                  //  updateUI(null);

                email അല്ലെങ്കിൽ  password തെറ്റാണു  error പേജിലോട്  പോവുക 

                }

                // ...
            }
        });


Thursday, 4 February 2016

Disable going back to previos Activity പഴയ അക്ടിവിടിയിലോട്ട് പോകുന്നത് ഒഴിവാക്കാന്‍

നമ്മുടെ  ആപ്പില്‍  ആദ്യം  കൊടുക്കുന്ന  സ്ക്രീന്‍ പിന്നീട്  ബാക്ക്  ബട്ടന്‍ പ്രസ്‌  ചെയ്തു എക്ഷിറ്റ് ചെയ്യുമ്പോള്‍ വരാതിരിക്കാന്‍ ഈ ചെറിയ  ഒരു വരി  കോഡ്  മതിയാകും .

 <activity
            android:name=".SplashActivity"
            android:noHistory="true"
            android:label="@string/app_name" >

ആണ്ട്രോയിട്  മാനിഫെസ്റ്റില്‍ പോയി  ഏതു  ആക്ടിവിടിയിലോട്ടാണോ പോകാതിരിക്കേണ്ടത്  അതില്‍  അതില്‍  ചെന്ന് ഈ  കോഡ്‌  android:noHistory="true" 
    അതില്‍ പോയി  പേസ്റ്റ്  ചെയ്യുക
ഇപ്പോള്‍ നിങ്ങളുടെ  AndroidManifest.xml fileഇല്‍  ഇത്  പോലെയിരിക്കും
 <activity
            android:name=".SplashActivity"
            android:noHistory="true"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

Wednesday, 6 August 2014

Android Database എങ്ങനെയുണ്ടാക്കാം

അന്ദ്രോയിദ് database പല രീതിയില്‍ ഉണ്ടാക്കാം
openOrCreateDatabase വെച്ചും extends SQLiteOpenHelper ക്ലാസ്സു വെച്ചും നിര്‍മിക്കാം
 ഞാനിവിടെ പെട്ടന്ന്അല്ലെങ്കില്‍ എളുപ്പത്തില്‍ എങ്ങനെ ഒരു database ഉണ്ടാക്കാമെന്ന് പറയാം

ഞാനിവിടെ ഉപയോഗിക്കുന്ന ത് openOrCreateDatabase കൊണ്ടുള്ള രീതിയാണ്‌

അന്ദ്രോയിദ് database ഉണ്ടാക്കുവാന്‍ ഒരറ്റ കമന്റ്‌ മതി
പക്ഷെ സാധാരണ അന്ദ്രോയിദ് database ഉണ്ടാക്കുവാന്‍ ഉപയോഗിക്കുന്ന രീതി ഇതല്ലെങ്കിലും ഇത് ഉപയോഗിച്ച് ഞാനുണ്ടാക്കിയ ആപ്പ് പ്രശനമില്ലാതെ തന്നെ വര്‍ക്ക്‌ ചെയ്യുന്നുണ്ട്
ഒന്നാമതായി database name കൊടുത്തു database ഉണ്ടാക്കാം
അതിനു സഹായിക്കുന്ന ഒരു ക്ലാസ്സാണ് SQLiteDatabase

step 1.create Database

SQLiteDatabase db;
db=openOrCreateDatabase("Home_DB",MODE_PRIVATE,null);

അടുത്തത് ഒരു databasil ഒരുപാട് tables ഉണ്ടാകും ഇതേ databasil ഒരു table ഉണ്ടാക്കുവാന്‍ ചെയ്യാന്‍ വേണ്ട കോഡ് ആണ്

Step 2. create a table

db.execSQL("create table if not exists personal_tb(_id INTEGER PRIMARY KEY AUTOINCREMENT,age INTEGER,weight INTEGER,height INTEGER,sex VARCHAR(50))");


Step 3.Finish

ഇനി എങ്ങനെ ഒരു databasil data insert ചെയ്യാമെന്ന് നോക്കാം

Step 4.inserting data to table

db=openOrCreateDatabase("Home_DB",MODE_PRIVATE,null);

db.execSQL("create table if not exists personal_tb(_id INTEGER PRIMARY KEY AUTOINCREMENT,age INTEGER,weight INTEGER,height INTEGER,sex VARCHAR(50))");

db.execSQL("insert into personal_tb(age,weight,height,sex) values ('"+age+"','"+Weight+"','"+Height+"','"+Sex+"')");

ഇനി എങ്ങനെ database display ചെയ്യാമെന്ന് നോക്കാം

Step 5 Display Databse

db=openOrCreateDatabase("MedicineDB",MODE_PRIVATE,null);

db.execSQL("create table if not exists personal_tb(age INTEGER,weight INTEGER,height INTEGER,sex VARCHAR(50))");
 String age=t1_Age;
 String age= t1_Height;
String age= t1_Weigh;
String age=t1_sex;
 Cursor cursor = db.rawQuery("SELECT * from personal_tb", null);
 
while(cursor.moveToNext()){
t1_Age=cursor.getString(0);
 t1_Height=cursor.getString(1);
 t1_Weight=cursor.getString(2);
 t1_sex=cursor.getString(3);
        }

Step 6 Delete a 10th row from database
int i=10;
db.execSQL("DELETE FROM personal_tb WHERE _id ='"+i+"'");

facebook whatsapp notification എങ്ങനെയുണ്ടാക്കാമെന്ന് നോക്കാം( in android)


firstly നമുക്ക് ഒരു activity ഉണ്ടാക്കണം

ActivityNotification.java
-------------------------------
notification ഉണ്ടാക്കാന്‍ വേണ്ട രണ്ടു മഹാ സംഭവങ്ങളാണ് :p
1.Notification
2.NotificationManager

ഈ രണ്ടു ക്ലാസ്സുകളും വെച്ച് രണ്ടു object ആദ്യം ഉണ്ടാക്കണം

private Notification notificationobj;
private NotificationManager notificationmngr_obj;

ആദ്യം notification service ആക്റ്റീവ് ആക്കണം അതിനു വേണ്ടി യുള്ള കോഡ് ആണ്
notificationmngr_obj=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

ഇനി notification കൊടുക്കുമ്പോള്‍ വേണ്ട കാര്യങ്ങള്‍ പറഞ്ഞു കൊടുക്കാം
അതിനു notification initialize ചെയ്യണം
അതിനു വേണ്ടി
notificationobj=new Notification(R.drawable.ic_launcher, "hello", 0);

ഇതില്‍ കൊടുത്ത ഭാഗങ്ങള്‍ ഓരോന്നായി പഠിക്കാം

Notification(icon, tickerText, when)
--------------------------------------
notification നില്‍ നമുക്ക് ഒരു icon സെറ്റ് ചെയ്യാം
notification നില്‍ tickerText അതായത് ഒരു heading കൊടുക്കാം
notification നില്‍  when അതായത് എപ്പോള്‍ notification വേണമെന്ന് പറഞ്ഞു കൊടുക്കാം ഞാന്‍ ഇവിടെ 0(പൂജ്യം)ആണ് കൊടുക്കുന്നത് അതായത് 0second ആകുമ്പോള്‍ notification കിട്ടും

ഇത് കൂടാതെ notification നമ്പറും കൂടെ കൊടുക്കാം

notificationobj.number=10;

Intent intent=new Intent(context,Activity2.class);
PendingIntent pIntent=PendingIntent.getActivity(context, 0, intent, 0);
ഈ രണ്ടു ക്ലാസുകള്‍ Intent ഉം PendingIntent ഉം
ഉപയോഗിക്കാം Intent എന്താണെന്ന്  മുന്നേ പറഞ്ഞിട്ടുണ്ട് ആവശ്യമുള്ളവര്‍ ഇവിടെ ക്ലിക്ക് ചെയ്യുക
PendingIntent എന്താണെന്നു അടുത്ത പോസ്റ്റില്‍ പറയാം

ഇനി വേണ്ടത് ഈ കൊടുത്തിരിക്കുന്ന ഇന്‍ഫര്‍മേഷന്‍ തമ്മില്‍ connect ചെയ്യാം

notification heading
String hello="hello";
String msg="mamstricks.com";

notificationobj.setLatestEventInfo(context, hello, msg, pIntent);

ഇനി NotificationManager വെച്ച് notification വിളിക്കാം

notificationmngr_obj.notify(0, notificationobj);

ഇനി notify കൊടുത്ത 0 എന്താണെന്ന് പറയാം അതാണ്‌ notification id ഇത് വെച്ച് വേണമെങ്കില്‍ notification cancel ചെയ്യാം അല്ലെങ്കില്‍ destroy ചെയ്യാം
notify(0, notificationobj);
 ഇനി notificationഇല്‍ ക്ലിക്ക് ചെയ്താല്‍ അത് cancel ചെയ്യുവാനും തിരിച്ചു ആപില്‍ എത്തുവാനും ഈ കോഡ് ഉപയോഗിക്കാം

 notificationobj.flags |= Notification.FLAG_AUTO_CANCEL;

full code
******************************************

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class ActivityNotificationextends Activity {

private Notification notificationobj;
private NotificationManager notificationmngr_obj;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
context=this;
}


public void viewNotify(View v){
String hello="hello";
String msg="messsage";
Intent intent=new Intent(context,ActivityNotification.class);
PendingIntent pIntent=PendingIntent.getActivity(context, 0, intent, 0);
notificationmngr_obj=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);


notificationobj=new Notification(R.drawable.ic_launcher, "hellook", 0);

notificationobj.number=10;
notificationobj.setLatestEventInfo(context, hello, msg, pIntent);


 
   notificationobj.flags |= Notification.FLAG_AUTO_CANCEL;

  notificationmngr_obj.notify(0, notificationobj);
 
}
}
***********************************************************************
മറ്റു രീതികല്‍  കൂടെ നോക്കാം
ഇവിടെ കൊടുത്ത കോഡ്
എങ്ങനെ പല രീതിയില്‍ ഉപയോഗിക്കാമെന്ന് നോക്കാം
1.
/**************/
notificationobj=new Notification(R.drawable.ic_launcher, "hellook", 0);

notificationobj.number=10;
notificationobj.setLatestEventInfo(context, hello, msg, pIntent);
/******************/
2.
/**************/
Notification notificationobj= new Notification.Builder(this)
       .setContentTitle("my title " + "mamstricks")
       .setContentText("Subject").setSmallIcon(R.drawable.ic_launcher)
       .setContentIntent(pIntent)
       .addAction(R.drawable.ic_launcher, "ok", pIntent)
       .addAction(R.drawable.ic_launcher, "more info", pIntent)
       .addAction(R.drawable.ic_launcher, "And more info", pIntent).build();
   noti.number=10;
/**************/
3.
/**************/
notificationobj=new Notification();

notificationobj.icon=R.drawable.ic_launcher;
notificationobj.tickerText="hellook";
notificationobj.number=10;
notificationobj.setLatestEventInfo(context, hello, msg, pIntent);
/**************/


facebook whatsapp notification എങ്ങനെയുണ്ടാക്കാമെന്ന് നോക്കാം( in android)


firstly നമുക്ക് ഒരു activity ഉണ്ടാക്കണം

ActivityNotification.java
-------------------------------
notification ഉണ്ടാക്കാന്‍ വേണ്ട രണ്ടു മഹാ സംഭവങ്ങളാണ് :p
1.Notification
2.NotificationManager

ഈ രണ്ടു ക്ലാസ്സുകളും വെച്ച് രണ്ടു object ആദ്യം ഉണ്ടാക്കണം

private Notification notificationobj;
private NotificationManager notificationmngr_obj;

ആദ്യം notification service ആക്റ്റീവ് ആക്കണം അതിനു വേണ്ടി യുള്ള കോഡ് ആണ്
notificationmngr_obj=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

ഇനി notification കൊടുക്കുമ്പോള്‍ വേണ്ട കാര്യങ്ങള്‍ പറഞ്ഞു കൊടുക്കാം
അതിനു notification initialize ചെയ്യണം
അതിനു വേണ്ടി
notificationobj=new Notification(R.drawable.ic_launcher, "hello", 0);

ഇതില്‍ കൊടുത്ത ഭാഗങ്ങള്‍ ഓരോന്നായി പഠിക്കാം

Notification(icon, tickerText, when)
--------------------------------------
notification നില്‍ നമുക്ക് ഒരു icon സെറ്റ് ചെയ്യാം
notification നില്‍ tickerText അതായത് ഒരു heading കൊടുക്കാം
notification നില്‍  when അതായത് എപ്പോള്‍ notification വേണമെന്ന് പറഞ്ഞു കൊടുക്കാം ഞാന്‍ ഇവിടെ 0(പൂജ്യം)ആണ് കൊടുക്കുന്നത് അതായത് 0second ആകുമ്പോള്‍ notification കിട്ടും

ഇത് കൂടാതെ notification നമ്പറും കൂടെ കൊടുക്കാം

notificationobj.number=10;

Intent intent=new Intent(context,Activity2.class);
PendingIntent pIntent=PendingIntent.getActivity(context, 0, intent, 0);
ഈ രണ്ടു ക്ലാസുകള്‍ Intent ഉം PendingIntent ഉം
ഉപയോഗിക്കാം Intent എന്താണെന്ന്  മുന്നേ പറഞ്ഞിട്ടുണ്ട് ആവശ്യമുള്ളവര്‍ ഇവിടെ ക്ലിക്ക് ചെയ്യുക
PendingIntent എന്താണെന്നു അടുത്ത പോസ്റ്റില്‍ പറയാം

ഇനി വേണ്ടത് ഈ കൊടുത്തിരിക്കുന്ന ഇന്‍ഫര്‍മേഷന്‍ തമ്മില്‍ connect ചെയ്യാം

notification heading
String hello="hello";
String msg="mamstricks.com";

notificationobj.setLatestEventInfo(context, hello, msg, pIntent);

ഇനി NotificationManager വെച്ച് notification വിളിക്കാം

notificationmngr_obj.notify(0, notificationobj);

ഇനി notify കൊടുത്ത 0 എന്താണെന്ന് പറയാം അതാണ്‌ notification id ഇത് വെച്ച് വേണമെങ്കില്‍ notification cancel ചെയ്യാം അല്ലെങ്കില്‍ destroy ചെയ്യാം
notify(0, notificationobj);
 ഇനി notificationഇല്‍ ക്ലിക്ക് ചെയ്താല്‍ അത് cancel ചെയ്യുവാനും തിരിച്ചു ആപില്‍ എത്തുവാനും ഈ കോഡ് ഉപയോഗിക്കാം

 notificationobj.flags |= Notification.FLAG_AUTO_CANCEL;

full code
******************************************

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

public class Activity2 extends Activity {

private Notification notificationobj;
private NotificationManager notificationmngr_obj;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
context=this;
}


public void viewNotify(View v){
String hello="hello";
String msg="messsage";
Intent intent=new Intent(context,Activity2.class);
PendingIntent pIntent=PendingIntent.getActivity(context, 0, intent, 0);
notificationmngr_obj=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);


notificationobj=new Notification(R.drawable.ic_launcher, "hellook", 0);

notificationobj.number=10;
notificationobj.setLatestEventInfo(context, hello, msg, pIntent);


 
   notificationobj.flags |= Notification.FLAG_AUTO_CANCEL;

  notificationmngr_obj.notify(0, notificationobj);
 
}
}
***********************************************************************
മറ്റു രീതികല്‍  കൂടെ നോക്കാം
ഇവിടെ കൊടുത്ത കോഡ്
എങ്ങനെ പല രീതിയില്‍ ഉപയോഗിക്കാമെന്ന് നോക്കാം
1.
/**************/
notificationobj=new Notification(R.drawable.ic_launcher, "hellook", 0);

notificationobj.number=10;
notificationobj.setLatestEventInfo(context, hello, msg, pIntent);
/******************/
2.
/**************/
Notification notificationobj= new Notification.Builder(this)
       .setContentTitle("my title " + "mamstricks")
       .setContentText("Subject").setSmallIcon(R.drawable.ic_launcher)
       .setContentIntent(pIntent)
       .addAction(R.drawable.ic_launcher, "ok", pIntent)
       .addAction(R.drawable.ic_launcher, "more info", pIntent)
       .addAction(R.drawable.ic_launcher, "And more info", pIntent).build();
   noti.number=10;
/**************/
3.
/**************/
notificationobj=new Notification();

notificationobj.icon=R.drawable.ic_launcher;
notificationobj.tickerText="hellook";
notificationobj.number=10;
notificationobj.setLatestEventInfo(context, hello, msg, pIntent);
/**************/


എങ്ങനെ ആണ്ട്രോയിട് sharepreference ഉപയോഗിച്ച് data സ്റ്റോര്‍ ചെയ്യാം


ഞാന്‍ രണ്ടു function ഉസ് ചെയ്തു കാണിക്കാം
ഒന്നാമത്തെ functionil data സ്റ്റോര്‍ ചെയ്തും രണ്ടാമത്തെ functionil data retrieve ചെയ്യാം

int k=1;notificationCount=1;
SharedPreferences pref;

First function on button click
**********************************
public void getDataa(View v){
k++;

notificationCount++;
pref = getApplicationContext().getSharedPreferences("MyPrefmams", MODE_PRIVATE); 
Editor editor = pref.edit();
editor.putInt("notificationCountkey", notificationCount);
editor.commit(); 
   Log.d("getdata_c_k"," "+notificationCount+" "+k);
}


 Second function with button click
*************************************************
public void getDat(View v){
pref=getSharedPreferences("MyPrefmams",this.MODE_PRIVATE);
notificationCount =pref.getInt("notificationCountkey", 0);
   Log.d("getdata_c_k"," "+notificationCount+" "+k);
}