Thursday, 10 October 2019

Shadow effect Elevation

<LinearLayout    android:layout_width="match_parent"    android:layout_height="200dp"    android:layout_gravity="center"    android:gravity="center"    android:layout_margin="20dp"    android:elevation="10dp"    android:clickable="true"    android:background="@drawable/ripple_effect2"    >
</LinearLayout>

<TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Elevation Example"    android:layout_gravity="center"    android:gravity="center"    android:elevation="5dp"    android:padding="20dp"    android:layout_marginTop="20dp"    android:layout_marginBottom="20dp"    android:background="@drawable/ripple_effect"    android:clickable="true"    ></TextView>






<?xml version="1.0" encoding="utf-8"?><ripple xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:color="#dddddd"    tools:targetApi="lollipop">

    <item android:id="@android:id/background">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"            android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <stroke                android:width="3dp"                android:color="#FFFFFF" />
            <corners android:bottomLeftRadius="15dp"                android:topLeftRadius="15dp"                android:bottomRightRadius="15dp"                android:topRightRadius="15dp" />
            <padding                android:bottom="0dp"                android:left="0dp"                android:right="0dp"                android:top="0dp" />
        </shape>
    </item>
</ripple>

Wednesday, 27 March 2019

Get Full Address From Latitude and Longitude Android Google Map

Get Full Address From Latitude and Longitude Android Google Map

String zipCode = getZipCode(MapsActivity.this,arg0.latitude,arg0.longitude);
Toast.makeText(MapsActivity.this,""+zipCode,Toast.LENGTH_LONG).show();





public String getZipCode(Context c, double lat, double lng){
    String fullAdd = null;
    String locality = null;
    String zip = null;
    String country = null;
    try {
        Geocoder geocoder = new Geocoder(c,Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocation(lat,lng,1);
        if (addresses.size()>0){
            Address address = addresses.get(0);
            fullAdd = address.getAddressLine(0);  // full Address  
            locality = address.getLocality();
            zip = address.getPostalCode();
            country = address.getCountryName();
        }

    }catch (IOException ex){
        ex.printStackTrace();
    }
    return zip;
}

Monday, 4 February 2019

SMS Permission Run time Android Studio

AndroidManifest.xml

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


MainActivity.java


package com.sjt.smspermissionruntime;
import android.Manifest;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkAndRequestPermissions()) {
// carry on the normal flow, as the case of permissions granted.
// Toast.makeText(SignUp.this,"Granted",Toast.LENGTH_LONG).show();
}
}
private boolean checkAndRequestPermissions() {
int permissionSendMessage = ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_SMS);
int locationPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS);
List<String> listPermissionsNeeded = new ArrayList<>();
if (locationPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.READ_SMS);
}
if (permissionSendMessage != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.RECEIVE_SMS);
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this,
listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]),
REQUEST_ID_MULTIPLE_PERMISSIONS);
return false;
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
Log.d("Permission", "Permission callback called-------");
switch (requestCode) {
case REQUEST_ID_MULTIPLE_PERMISSIONS: {
Map<String, Integer> perms = new HashMap<>();
// Initialize the map with both permissions
perms.put(Manifest.permission.READ_SMS, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.RECEIVE_SMS, PackageManager.PERMISSION_GRANTED);
// Fill with actual results from user
if (grantResults.length > 0) {
for (int i = 0; i < permissions.length; i++)
perms.put(permissions[i], grantResults[i]);
// Check for both permissions
if (perms.get(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED
&& perms.get(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED) {
Log.d("sms", "READ_SMS & RECEIVE_SMS services permission granted");
// process the normal flow
//else any one or both the permissions are not granted
} else {
Log.d("Some", "Some permissions are not granted ask again ");
//permission is denied (this is the first time, when "never ask again" is not checked) so ask again explaining the usage of permission
// // shouldShowRequestPermissionRationale will return true
//show the dialog or snackbar saying its necessary and try again otherwise proceed with setup.
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_SMS) ||
ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECEIVE_SMS)) {
showDialogOK("READ_SMS and RECEIVE_SMS Services Permission required for this app",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
checkAndRequestPermissions();
break;
case DialogInterface.BUTTON_NEGATIVE:
// proceed with logic by disabling the related features or quit the app.
break;
}
}
});
}
//permission is denied (and never ask again is checked)
//shouldShowRequestPermissionRationale will return false
else {
// Toast.makeText(this, "Go to settings and enable permissions", Toast.LENGTH_LONG).show();
// //proceed with logic by disabling the related features or quit the app.
}
}
}
}
}
}
private void showDialogOK(String message, DialogInterface.OnClickListener okListener) {
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("OK", okListener)
.setNegativeButton("Cancel", okListener)
.create()
.show();
}
}