Tuesday, 26 September 2017

Sms_reader_auto



-----------------------------------------manifest-----------------------------

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="io.github.swarajsaaj.otpblogdemo">

    <uses-permission android:name="android.permission.RECEIVE_SMS" >
    </uses-permission>
    <uses-permission android:name="android.permission.READ_SMS" />


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

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



        <receiver android:name=".SmsReceiver">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
            </intent-filter>
        </receiver>



    </application>

</manifest>









--------------------------MainActivity.java--------------------------------


package io.github.swarajsaaj.otpblogdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    EditText messageotp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        messageotp = (EditText) findViewById(R.id.messageotp);

        SmsReceiver.bindListener(new SmsListener() {
            @Override
            public void messageReceived(String messageText) {
                Log.d("Text", messageText);
                Toast.makeText(MainActivity.this,"Message: "+messageText,Toast.LENGTH_LONG).show();

            }
        });
    }
}




---------------------------SmsListener.class-------------


package io.github.swarajsaaj.otpblogdemo;

public interface SmsListener {

        public void messageReceived(String messageText);

}







-----------------------------SmsReceiver.class---------------------------- 


package io.github.swarajsaaj.otpblogdemo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

public class SmsReceiver extends BroadcastReceiver {

    private static SmsListener mListener;

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle data  = intent.getExtras();

        Object[] pdus = (Object[]) data.get("pdus");

        for(int i=0;i<pdus.length;i++){
            SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);

            String sender = smsMessage.getDisplayOriginatingAddress();
            //You must check here if the sender is your provider and not another one with same text.

            String messageBody = smsMessage.getMessageBody();

            //Pass on the text to our listener.
            mListener.messageReceived(messageBody);
        }

    }

    public static void bindListener(SmsListener listener) {
        mListener = listener;
    }
}

IMPORTANT LINKS





Library for Google Direction API for Google Maps Android API v2


https://github.com/akexorcist/Android-GoogleDirectionLibrary



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






Android library to easily serialize and cache your objects to disk using key/value pairs.

 

 https://github.com/anupcowkur/Reservoir

 

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



http://www.viralandroid.com/2015/12/how-to-get-current-gps-location-programmatically-in-android.html




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




Android - Count Power button clicks and Start Activity


https://stackoverflow.com/questions/15609008/android-count-power-button-clicks-and-start-activity






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

Android Get Address with Street Name, City for Location with Geocoding



http://javapapers.com/android/android-get-address-with-street-name-city-for-location-with-geocoding/


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


How to pass Bitmap images from one activity to another


https://www.youtube.com/watch?v=jwQDGZQOhh4



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


How To Integrate Youtube API In Android Application


https://www.youtube.com/watch?v=a4NT5iBFuZs




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


Provide multiple language support in your android app   


https://bhavyanshu.me/tutorials/provide-multiple-language-support-in-your-android-app/08/20/2015






Monday, 18 September 2017

Tab layout




---------------------------tab.xml------------------------------------------



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Tab 1"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
</RelativeLayout>









--------same as add tab1,tab2 xml create




--------------------Tab.java----------------

package com.httpabcdefapp1123.newdesignapp.Agencyclass;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.httpabcdefapp1123.newdesignapp.R;

/** * Created by meenakshi on 9/18/2017. */
public class Active_user_caregiver extends Fragment {

    //Overriden method onCreateView  
  @Nullable 
   @Override   
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        //Returning the layout file after inflating        //Change R.layout.tab1 in you classes        return inflater.inflate(R.layout.active_user_caregiver, container, false);
    }
}





--------same as add tab1,tab2 java create



--------------pager adapter-----------------------------------



package com.httpabcdefapp1123.newdesignapp.AgencyAdapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.httpabcdefapp1123.newdesignapp.Agencyclass.Active_user_caregiver;
import com.httpabcdefapp1123.newdesignapp.Agencyclass.Payment_history;
import com.httpabcdefapp1123.newdesignapp.Agencyclass.Cancelled;
import com.httpabcdefapp1123.newdesignapp.Agencyclass.Inactive;
import com.httpabcdefapp1123.newdesignapp.Agencyclass.Working;

/** * Created by meenakshi on 9/18/2017. */
public class Pager extends FragmentStatePagerAdapter {
    //integer to count number of tabs  
  int tabCount;

    //Constructor to the class   
 public Pager(FragmentManager fm, int tabCount) {
        super(fm);
        //Initializing tab count  
      this.tabCount= tabCount;
    }

    //Overriding method getItem  
  @Override
    public Fragment getItem(int position) {
        //Returning the current tabs   
     switch (position) {
            case 0:
                Tab tab = new Tab ();
                return tab1;
            case 1:
                Cancelled tab2 = new Cancelled();
                return tab2;
            case 2:
                Inactive tab3 = new Inactive();
                return tab3;
          
            default:
                return null;
        }
    }

    //Overriden method getCount to get the number of tabs   
 @Override   
 public int getCount() {
        return tabCount;
    }
}


------------activity_main.xml-------------------------------

<RelativeLayout 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:id="@+id/main_layout"   
 android:layout_width="match_parent" 
   android:layout_height="match_parent">

    <include layout="@layout/tool_bar" />
    <!-- our toolbar -->

    <!-- our tablayout to display tabs  -->   
 <android.support.design.widget.TabLayout   
     android:id="@+id/tabLayout"      
  android:layout_below="@+id/tool_bar"  
      android:layout_width="match_parent"
       android:layout_height="wrap_content" />

    <!-- View pager to swipe views -->  
  <android.support.v4.view.ViewPager      
  android:id="@+id/pager"     
   android:layout_below="@+id/tabLayout"
        android:layout_width="match_parent" 
       android:layout_height="fill_parent"    
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</RelativeLayout>





-----AgencyfragmentActivity.java-----------


package com.httpabcdefapp1123.newdesignapp.Activity.AgencySide;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.os.Bundle;

import com.httpabcdefapp1123.newdesignapp.Activity.BaseActivity;
import com.httpabcdefapp1123.newdesignapp.AgencyAdapter.Pager;
import com.httpabcdefapp1123.newdesignapp.R;

public class AgencyfragmentActivity extends BaseActivity implements TabLayout.OnTabSelectedListener {

     TabLayout tabLayout;

     ViewPager viewPager;

    @Override 
   protected int getContentResId() {
        return R.layout.activity_agencyfragment;
    }

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setToolbarWithBackButton("SYZYGY");

        viewPager = (ViewPager) findViewById(R.id.pager);

        tabLayout = (TabLayout) findViewById(R.id.tabLayout);



        //Adding the tabs using addTab() method   
     tabLayout.addTab(tabLayout.newTab().setText("Payment History"));
        tabLayout.addTab(tabLayout.newTab().setText("Cancelled"));
        tabLayout.addTab(tabLayout.newTab().setText("Inactive"));
        tabLayout.addTab(tabLayout.newTab().setText("Working"));
        tabLayout.addTab(tabLayout.newTab().setText("Active User Caregiver"));
        tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);


        Pager adapter = new Pager(getSupportFragmentManager(), tabLayout.getTabCount());
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

        //Adding adapter to pager   
     viewPager.setAdapter(adapter);

        //Adding onTabSelectedListener to swipe views 
       tabLayout.setOnTabSelectedListener(this);
    }

    @Override    public void onTabSelected(TabLayout.Tab tab) {

        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override    public void onTabReselected(TabLayout.Tab tab) {

    }
}




----------build.gradle(depenecy)-----------


compile 'com.android.support:design:25.3.1'


Friday, 15 September 2017

Thread run every 10 second

-----------------yellow lines you add--------------------


-----------------------MainActivity.java-----------------------------------



package com.example.meenakshi.myalarm;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;import android.widget.Toast;
public class Main2Activity extends AppCompatActivity {
    Handler mHandler = new Handler();   
 @Override   
 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        new Thread(new Runnable() {
            @Override       
     public void run() {
                // TODO Auto-generated method stub 
               while (true) {
                    try {
                        Thread.sleep(10000);
                        mHandler.post(new Runnable() {

                            @Override 
                           public void run() {

            Toast.makeText(Main2Activity.this, "run...", Toast.LENGTH_SHORT).show();
             // TODO Auto-generated method stub 
           // Write your code here to update the UI.      
                      }
                        });
                    } catch (Exception e) {
                        // TODO: handle exception    
                }
                }
            }
        }).start();

    }
}

Alarm manager





-------------------activity_main.xml----------------------


<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" 
   tools:context=".MainActivity" >

    <EditText      
  android:id="@+id/time"  

      android:layout_width="wrap_content"   
     android:layout_height="wrap_content"  
      android:layout_alignParentLeft="true"  
      android:layout_alignParentTop="true"  
      android:layout_marginTop="28dp"      
  android:ems="10"

        android:hint="Number of seconds"  
      android:inputType="numberDecimal" />

    <Button     
   android:id="@+id/button1" 
       android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
       android:layout_alignRight="@+id/time" 
       android:layout_below="@+id/time"   
     android:layout_marginRight="60dp"   
     android:layout_marginTop="120dp"  
      android:text="Start" />

</RelativeLayout>





--------------MainActivity---------------



package com.example.meenakshi.myalarm;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
    Button b1;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1=(Button) findViewById(R.id.button1);

        b1.setOnClickListener(new View.OnClickListener() {

            @Override       
     public void onClick(View v) {
                // TODO Auto-generated method stub    
            startAlert();
            }
        });

    }
    public void startAlert() {
        EditText text = (EditText) findViewById(R.id.time);
        int i = Integer.parseInt(text.getText().toString());
        Intent intent = new Intent(this, MyBroadcastReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(
                this.getApplicationContext(), 234324243, intent, 0);
        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                + (i * 1000), pendingIntent);
        Toast.makeText(this, "Alarm set in " + i + " seconds",Toast.LENGTH_LONG).show();
    }

}




------------MyBroadcastReceiver.CLASS---------



package com.example.meenakshi.myalarm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Handler;
import android.widget.Toast;

/** * Created by shirsh on 9/15/2017. */
public class MyBroadcastReceiver extends BroadcastReceiver {
    Handler mHandler = new Handler();

    MediaPlayer mp;
    @Override 
   public void onReceive(final Context context, Intent intent) {
        mp=MediaPlayer.create(context, R.raw.shape);


//shape is mp3 song.they add in raw folder
        mp.start();
        Toast.makeText(context, "run...", Toast.LENGTH_SHORT).show();


    }
}



---------AndroidManifest.xml---------------

<receiver android:name=".MyBroadcastReceiver"></receiver>

AutoComplete Address (Updated)

-------------------------------------Activity---------------------------------- package placeautocomplete.iteritory.com; import androi...