• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Android - Google API and fragments

Joined
Mar 21, 2009
Messages
6,190 (1.12/day)
Location
Midlands,UK
System Name Ultraman
Processor Intel core i9 13900HK
Motherboard Alienware/Dell inverted motherboard
Cooling Alienware/Dell cooling solution + IETS GT500 cooling pad
Memory Alienware/Dell 32GB 6000mhz DDR5
Video Card(s) Nvidia RTX4080 12GB
Storage 1TB Dell supplied NVME + Samsung Evo 1TB NVME
Display(s) AOC Gaming CU34G3S/BK
Case Alienware X16
Audio Device(s) onboard/Speakers: Logitech G560
Power Supply Alienware/Dell battery + 330W charger
Mouse Microsoft Pro Intellimouse - White
Keyboard Ducky One2 SF White MX cherry Red
Software Windows 11
Hello all,need some help with my program. So i was following this tutorial: http://www.androidhive.info/2015/02/android-location-api-using-google-play-services/
and i have 2 major error in my code which i can't seem to fix apart from changing the Fragment class to Fragment Activity,but when i do i get problems with the Navigation drawer which tells me i need change it which i understand how but i also get problem with that.
But i want first see if i can fix the code without changing the Fragment class,the 2 errors i get are:
1st says GooglePlayServicesAvailable(android.context.Context) in GooglePlayService.Util cannot be applied and GeterrorDialog() in GooglePlayService.Util cannot be applied to because its not an Activity class which i have established.
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
Play_Service).show();
}
}
return false;
}
2nd error Builder(android.context.Context) cannot be applied:
protected synchronized void buildGoogleApiClient() {
GoogleAPI = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
}

Is there any way to work around this without changing the Fragment to a FragmentActivity class?
If i have to change to FragmentActivity how would i work about fixing this part:
I have highlighted the main problem and i understand i need use getSupportFragmentManager but when i do change it and import correctly i get the same problem still.
Fragment fragments = null;

switch (position) {
case 0:
fragments = new pedometer();
break;
case 1:
fragments = new map();
break;
case 2:
fragments = new statspage();
}

FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragments)
.commit();
}
 
Joined
Oct 2, 2005
Messages
3,059 (0.45/day)
Location
Baltimore MD
Processor Ryzen 5900X
Motherboard ASUS Prime X470 Pro
Cooling Arctic liquid freezer II 240
Memory 2 x 16 Gb Gskill Trident Z 3600 Mhz
Video Card(s) MSI Ventus 3060 Ti OC
Storage Samsung 960 EVO 500 Gb / 860 EVO 1 Tb
Display(s) Dell S2719DGF
Case Lian Li Lancool II Mesh
Audio Device(s) Soundblaster Z
Power Supply Corsair RM850x
Mouse Logitech G703
Keyboard Logitech G513
Software Win 11
Not to sound like a dick but XDA developers would be a much better place for this, not many android people here.

Try the general section http://forum.xda-developers.com/android some one there can definately help you.
 
Joined
Mar 21, 2009
Messages
6,190 (1.12/day)
Location
Midlands,UK
System Name Ultraman
Processor Intel core i9 13900HK
Motherboard Alienware/Dell inverted motherboard
Cooling Alienware/Dell cooling solution + IETS GT500 cooling pad
Memory Alienware/Dell 32GB 6000mhz DDR5
Video Card(s) Nvidia RTX4080 12GB
Storage 1TB Dell supplied NVME + Samsung Evo 1TB NVME
Display(s) AOC Gaming CU34G3S/BK
Case Alienware X16
Audio Device(s) onboard/Speakers: Logitech G560
Power Supply Alienware/Dell battery + 330W charger
Mouse Microsoft Pro Intellimouse - White
Keyboard Ducky One2 SF White MX cherry Red
Software Windows 11
Top