Getting Started
Layouts
Gradle
RecyclerView onClickListeners
NavigationView
Intent
JSON handling with org.json
Android Studio
Resources
Data Binding Library
Exceptions
Getting Calculated View Dimensions
AsyncTask
SharedPreferences
Emulator
Material Design
Lint Warnings
Service
Storing Files in Internal and External Storage
WebView
Project SDK versions
RecyclerView
Google Maps
PorterDuff Mode
9-Patch images
Android NDK
RecyclerView Decorations
Camera 2 API
ViewPager
CardView
HttpURLConnection
SQLite
ADB Android Debug Bridge
ButterKnife
Supporting different screen resolutions
Glide
Retrofit2
Dialog
ACRA
GreenDAO
Formatting Strings
Notifications
AlarmManager
Fragments
Handler
Creating Custom Views
BroadcastReceiver
Activity
Snackbar
Runtime Permissions in API-23
Logging and using Logcat
VectorDrawable and AnimatedVectorDrawable
Tools Attributes
Toast
Interfaces
Animators
Location
Theme Style Attribute
The Manifest File
Parcelable
MediaPlayer
Multidex and the Dex Method Limit
Data Synchronization with Sync Adapter
Menu
Instant Run in Android Studio
Picasso
Bluetooth LE API
RoboGuice
Memory Leaks
Universal Image Loader
Volley
Widgets
Date and Time Pickers
Integrate Google Sign In
In-app billing
FloatingActionButton
ContentProvider
Dagger 2
Realm
Unit testing in Android with JUnit
Android Versions
Wi-Fi Connections
SensorManager
Localization with resources
ProgressBar
Custom Fonts
Vibration
Google Awarness APIs
Text to Speech (TTS)
UI Lifecycle
Spinner
Data Encryption / Decryption
Testing UI with Espresso
Writing UI tests
GreenRobot EventBus
OkHttp
Enhancing Performance Using Icon Fonts
Handling Depp Links
Canvas drawing using SurfaceView
Firebase
Crash Reporting Tools
Check Internet Connectivity
Facebook SDK
Unzip File
Android Places API
Creating your own libraries
Handling JSON with Gson
Device Display Metrics
TextView
ListView
Building Backwards Compatible Apps
Loader
ProGuard - Obfuscating and Shrinking your code
Detect Shake Event
Typedef Annotations
Capturing Screenshots
MVP Architecture
Orientation Changes
Xposed
Security
PackageManager
ImageView
Gesture Detection
Doze Mode
Android Sound and Media
SearchView
Camera and Gallery
Callback URL
Twitter APIs
SqlCipher integration
Drawables
Colors
ConstraintLayout
RenderScript
Fresco
Swipe to Refresh
AutoCompleteTextView
Installing apps with ADB
IntentService
AdMob
Implicit Intents
Publish to Play Store
Firebase Realtime Database
Image Compression
Email Validation
Keyboard
Button
TextInputLayout
Bottom Sheets
CoordinatorLayout and Behaviors
EditText
Paypal Gateway Integration
Firebase App Indexing
Firebase Crash Reporting
Displaying Google Ads
Vk SDK
Localized DateTime
Count Down Timer
Reading Barcode and QR codes
Otto Event Bus
TransitionDrawable
Port Mapping using Cling
Creating Overlay always-on-top Windows
ExoPlayer
Inter-app UI testing with UIAutomator
MediaSession
Speech to Text Conversion
FileProvider
Publish .aar file to Apache Archive with Gradle
XMPP
Authenticator
RecyclerView and LayoutManagers
AudioManager
Job Scheduling
Accounts and AccountManager
OpenCV
Split Screen Multi-Screen Activities
Threads
MediaStore
Time Utils
Touch Events
Fingerprint API
MVVM Architecture
BottomNavigationView
ORMLite
YouTube API
TabLayout
Retrofit2 with RxJava
DayNight Theme AppCompat
ShortcutManager
LruCache
Using Jenkins CI
Zip files
Vector Drawables
Fastlane
Define step value for RangeSeekBar
Getting started with OpenGL ES 2.0
Check Data Connection
Java Native Interface (JNI)
FileIO
Perfomance Optimization
Robolectric
Moshi
Strick Mode Policy
Internalization and localization
Retrolambda
SparseArray
Firebase Cloud Messaging
Shared Element Transitions
Android Things
VideoView
ViewFlipper
Dependency Injection with Dagger 2
Formatting phone numbers
Storing password securely
Android Kernel Optimization
Paint
AudioTrack
ProGuard
Create Android Custom ROMs
Java on Android
Pagination in RecyclerVi
Genymotion for Android
Handling touch and motion events
Creating Splash screen
ConstraintSet
CleverTap
Publish library to Maven repositories
ADB shell
Ping ICMP
AIDL
Using Kotlin
Autosizing TextView
Signing apps for release
Context
Activity Recognition
Secure SharedPreferences
Secure SharedPreferences
Bitmap Cache
Android x86 in VirtualBox
JCodec
Design Patterns
Okio
Google SignIn integration
TensorFlow
Game developmen
Notification Channel
Bluetooth Low Energy (LE)
Leak Canary
FuseView
SQLite using ContentValues
Enhancing Alert Dialogs
Hardware Button Events, Intents PTT
SpannableString
Looper
Optimized VideoView
Google Drive API
Animated AlertDialog Box
Annotation Processor
SyncAdapter with periodically do sync of data
Singleton Class for Toast Message
Fastjson
Android Architecture Components
Jackson
Play Store
Loading Bitmaps Effectively
Getting system font names
Smartcard
Convert vietnamese string to english
Contributors

Getting Current Places by Using Places API

suggest change

You can get the current location and local places of user by using the Google Places API.

Ar first, you should call the PlaceDetectionApi.getCurrentPlace() method in order to retrieve local business or other places. This method returns a PlaceLikelihoodBuffer object which contains a list of PlaceLikelihood objects. Then, you can get a Place object by calling the PlaceLikelihood.getPlace() method.

Important: You must request and obtain the ACCESS_FINE_LOCATION permission in order to allow your app to access precise location information.

private static final int PERMISSION_REQUEST_TO_ACCESS_LOCATION = 1;

private TextView txtLocation;
private GoogleApiClient googleApiClient;

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

    txtLocation = (TextView) this.findViewById(R.id.txtLocation);
    googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Places.GEO_DATA_API)
            .addApi(Places.PLACE_DETECTION_API)
            .enableAutoManage(this, this)
            .build();

    getCurrentLocation();
}

private void getCurrentLocation() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Log.e(LOG_TAG, "Permission is not granted");

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

    Log.i(LOG_TAG, "Permission is granted");
    
    PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace(googleApiClient, null);
    result.setResultCallback(new ResultCallback<PlaceLikelihoodBuffer>() {
        @Override
        public void onResult(PlaceLikelihoodBuffer likelyPlaces) {
            Log.i(LOG_TAG, String.format("Result received : %d " , likelyPlaces.getCount() ));
            StringBuilder stringBuilder = new StringBuilder();

            for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                stringBuilder.append(String.format("Place : '%s' %n",
                        placeLikelihood.getPlace().getName()));
            }
            likelyPlaces.release();
            txtLocation.setText(stringBuilder.toString());
        }
    });
}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case PERMISSION_REQUEST_TO_ACCESS_LOCATION: {
            // If the request is cancelled, the result arrays are empty.
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                getCurrentLocation();
            } else {
                // Permission denied, boo!
                // Disable the functionality that depends on this permission.
            }
            return;
        }

        // Add further 'case' lines to check for other permissions this app might request.
    }
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    Log.e(LOG_TAG, "GoogleApiClient connection failed: " + connectionResult.getErrorMessage());
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents