Finding Current Location Example using Android Studio with Android 6.0 Runtime Permissions

Output Screen Shots:

Example Code :
------------------
Note : Before to understand this example please go through Android 6.0 Runtime permissions tutrials below
http://ramsandroid4all.blogspot.in/2015/12/requesting-permissions-at-run-time-in.html

AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ramsandroid.findingcurrentlocation">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <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>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

activity_main.xml:
<?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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

MainActivity.java:
package com.ramsandroid.findingcurrentlocation;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationManager;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    static final int REQUEST_LOCATION = 1;
    LocationManager locationManager;

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

        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        getLocation();
    }

    void getLocation() {
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission
                (this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);

        } else {
            Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            if (location != null) {
                double latti = location.getLatitude();
                double longi = location.getLongitude();

                ((TextView) findViewById(R.id.textView)).
                        setText("Current Location is :" + latti + "," + longi);
            } else {
                ((TextView) findViewById(R.id.textView)).
                        setText("Unable to find current location . Try again later");
            }

        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        switch (requestCode) {
            case REQUEST_LOCATION:
                getLocation();
                break;
        }
    }

}


 

How to add Animated Splash Screen to you Android App using Android Studio


In this tutorial i show you how to add Animated Splash Screen to your Android Application using Android Studio. You can add this Splash Screen either to existing Android Studio Project or New Android Studio Project.

       Code necessary for the implementation can be copied from here and watch the video below for the detail explanation of the implementation.



Splashscreen.java


layout/activity_splashscreen.xml

anim/alpha.xml

anim/translate.xml

Copy an image with name splash_img in png format.


So this is the simple way to add Animated Splashscreen to you Android App. 

XPERIA Cars Road Trip Theme for Xperia C [PORTED]



Hi All I ported XPERIA Cars Road Trip Theme for Xperia C and all Sony Android 4.2.2 Device

Requirements:

1. Rooted Sony Xperia C or any Sony Android 4.2.2 Device
2. ES File Explorer

Installation Procedure:

- Download XPERIA Cars Road Trip Theme for Xperia C and copy it to your SD Card
- Open ES File Explorer and copy file to Device/system/app folder and reboot (Make sure you have given super user permission to ES File Exporer and permissions set to -rw -rw -r)

Note: If you Want to change theme name don't give any spaces in name.

Setup Android Studio in offline mode On Windows for Beginners

Android Studio For Beginners


I have explained everything in detail in Video present at bottom of post

Download links for Required  files for setting up Android Studio




How to decompile APK Files and get Source Code ( JAVA & XML )

Decompile APK Files and get Source Code ( JAVA & XML )


Requirements:

4. Your APK file to decompile

Watch Below Video For Detailed Steps:



How to Stop or Disable Windows Updates in Windows 10 all Versions Permanently

How to Stop or Disable Windows Updates in Windows 10 all Versions Permanently 

Microsoft has removed option to stop windows updates from auto downloading. Which is a major bug because it wastes your bandwidth in background by downloading Windows updates without out knowledge.
This tutorial helps you to stop annoying Windows updates and save your data.

I have Explained every thing in very detail here. Still having problem to follow, don't worry watch video below to see live demonstration.

Steps:

1. Press Windows + R on Keyboard
2. You will get window Like Below

3. Type services.msc in Run Window and Click on OK
4.You will get image like below

5. Scroll down until you find Windows Update Right Click On it and Select properties

6. Now Select on Startup type drop down menu and select Disabled

7. Then Click on stop and click on OK
8. Then Close all windows
9. Open This PC and Navigate to C:\Windows\System32\drivers\etc\
10. You Will see a File with name hosts. Copy that file to Desktop and Open it with Notepad++ OR any text editor  and  add  following Lines at bottom as  shown in Image below and save it.
# windowsupdate.microsoft.com
127.0.0.1 windowsupdate.microsoft.com
127.0.0.1 www.windowsupdate.microsoft.com
127.0.0.1 v4.windowsupdate.microsoft.com
127.0.0.1 www.v4.windowsupdate.microsoft.com
# windowsupdate.com
127.0.0.1 windowsupdate.com
127.0.0.1 www.windowsupdate.com
127.0.0.1 download.windowsupdate.com
127.0.0.1 www.download.windowsupdate.com
127.0.0.1 v4.windowsupdate.com
127.0.0.1 www.v4.windowsupdate.com
# windowsupdate.microsoft.nsatc.net
127.0.0.1 windowsupdate.microsoft.nsatc.net
127.0.0.1 v4windowsupdate.microsoft.nsatc.net
# wustat.windows.com
127.0.0.1 wustat.windows.com


11. Now copy that file again back to C:\Windows\System32\drivers\etc 

12. Windows will ask you replace file click on Continue.

Professional Android WebView Application With Splash Screen and Share Button.


In this Tutorial I will teach you how to make Professional looking Android WebView Application.

Part I


Part II



Features:

Having Splash Screen
Loading Animation before Website Loads into App
Share Button on The Action Bar.

Requirements:

Windows or Mac Computer With
Android Studio & JDK 7 Installed
No need of Knowledge of Coding
Little Brain. 

NOTE: In this guide i will be asking you to copy and paste code into your file. That indicates you first remove complete code particular file and paste my code.

Steps :

Open Android Studio and Select File=>New Project.

Follow Screens.....


Set Application Name and package name what ever you want.


Select Target SDK as per your Needs



Don't change these details

Now Navigate to MainActivity.java and double click on it.



Now Copy and Paste below Code into MainActivity.java file. Replace my project name with your's in 1st line of code. In Line No 27 replace "http://karthiktechfreak.blogspot.in/" with your url. Don't use www. prfix. paste in same same format you are looking. Next Change custom share data in red color with lines you want to sown share message in line numbers 71 & 72  and give your website url  in line 27th Line
Now Right Click on your Project name udnder java folder and select create New Class and Name it Splash and copy and paste below code into Splash.java file. Replace my project name with your's in 1st line of code
Now Create one more java class file like above and name it as MyAppWebViewClient now copy and paste below code into MyAppWebViewClient.java file. And give your website url without any www or http prefixes as i gave there in line number 15 Replace my project name with your's in 1st line of code

Now we are done with Java Files. If android studio shows any errors ignore them. All errors will be gone by the end of this tutorial.

Now Copy Below Code into activity_main.xml

Now We Will Create new layout under folder layouts. For that Right Click on Layout and select new Xml File as shown in below figure. Name Layout as activity_splash.


Now Copy and Paste Below Code into activity_splash.xml




Now open menu_main.xml in menu folder and paste below code into it.

Now Open AndroidManifest.xml file From manifests folder and copy below code into it. replace project name with your project name in the 3rd line


Now Finally Open Values Folder and place below code in strings.xml and change app_name string value to yours in line number two.
By this we had finished all coding Part.

Now open computer and navigate to your Project folder YourProjectName\app\src\main\res, there will be four folders with name mipmap change ic_launcher.png with your icon but don't change name and only png format are supported. And place an image file with name vert_loading.png in all folders. vert_loading.png will be your Startup screen.

At last our Project structure looks like below image...


Now go to buil in top menu of Android Studio and select Generate signed Apk and epxort your Application. After Succesfull export copy it to your phone and install. Or Upload to play store.

Watch how to Generate Signed Apk in Android Studio.



 
|