Google Play Services - Activity Recognition Freezes After a Few Results - java

I have tried to simplify my code as much as possible, basically hte issue is that the ActivityRecognitionIntentService appears to be called a couple of times, then stalls out. It appears to be related to the requestCode in the PendingIntent, but I am not sure, can someone please advise me as to what is going wrong? Thanks.
Dashboard.java
public class Dashboard extends Activity implements GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener {
private BroadcastReceiver receiver;
private TextView tvActivity;
private GoogleApiClient mGoogleApiClient;
//String Locationp = "null";
//private LocationRequest mLocationRequest;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
tvActivity = (TextView) findViewById(R.id.tvActivity);
int resp =GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(resp == ConnectionResult.SUCCESS){
// Create a GoogleApiClient instance
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(ActivityRecognition.API)
//.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
}
else{
Toast.makeText(this, "Please install Google Play Service.", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onConnected(Bundle arg0) {
Intent i = new Intent(this, ActivityRecognitionIntentService.class);
PendingIntent mActivityRecognitionPendingIntent = PendingIntent.getService(this, 2000, i, PendingIntent.FLAG_UPDATE_CURRENT);
Log.e("MAIN", "Connected to ActRec");
ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(mGoogleApiClient, 1000, mActivityRecognitionPendingIntent);
}
#Override
public void onConnectionSuspended(int arg0) {
Log.e("MAIN", "Connection suspended to ActRec");
}
#Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.e("MAIN", "Not Connected to ActRec");
}
ActivityRecognitionIntentService.java
public class ActivityRecognitionIntentService extends IntentService {
public ActivityRecognitionIntentService() {
super("ActivityRecognitionIntentService");
}
protected void onHandleIntent(Intent intent) {
if (ActivityRecognitionResult.hasResult(intent)) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
DetectedActivity mostProbAct = result.getMostProbableActivity();
int confidence = mostProbAct.getConfidence();
String mostProbActName = getActivityName(mostProbAct.getType());
Intent i = new Intent("com.xxx.abc.ACTIVITY_RECOGNITION_DATA");
i.putExtra("act", mostProbActName);
i.putExtra("confidence", confidence);
Log.e("ARS", mostProbActName + "," + confidence);
//sendBroadcast(i);
} else
Log.e("ARS", "Intent had no ActivityRecognitionData");
}
private String getActivityName(int activityType) {
switch (activityType) {
case DetectedActivity.IN_VEHICLE:
return "in_vehicle";
case DetectedActivity.ON_BICYCLE:
return "on_bicycle";
case DetectedActivity.ON_FOOT:
return "on_foot";
case DetectedActivity.STILL:
return "still";
case DetectedActivity.UNKNOWN:
return "unknown";
case DetectedActivity.TILTING:
return "tilting";
}
return "unknown";
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tigerblood.com.node" >
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<service android:enabled="true" android:name="com.xxx.abc.ActivityRecognitionIntentService"></service>
<activity
android:name="com.tigerblood.node.Dashboard"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Related

My app keeps crashing after splash activity finishes

my app when I run it only shows the splash screen then crashes.
at first it was giving me "app keep on stopping" when I run it but now it runs the splash screen then crashes.
Splash screen.
public class SplashActivity extends AppCompatActivity {
SharedPreferences sharedPreferences;
private boolean mIsBackButtonPressed;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash);
sharedPreferences=getSharedPreferences(Constants.pref_name,MODE_PRIVATE);
new Handler().postDelayed(new Runnable() {
public void run() {
if (!mIsBackButtonPressed) {
if(getIntent().hasExtra("action_type")){
Intent intent= new Intent(SplashActivity.this, MainActivity.class);
String action_type=getIntent().getExtras().getString("action_type");
String receiverid=getIntent().getExtras().getString("senderid");
String title=getIntent().getExtras().getString("title");
String icon=getIntent().getExtras().getString("icon");
intent.putExtra("icon",icon);
intent.putExtra("action_type",action_type);
intent.putExtra("receiverid",receiverid);
intent.putExtra("title",title);
startActivity(intent);
finish();
}
else
GPSStatus();
}
}
}, 2000);
}
public void onBackPressed() {
// set the flag to true so the next activity won't start up
mIsBackButtonPressed = true;
super.onBackPressed();
}
public void GPSStatus(){
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean GpsStatus = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if(!GpsStatus)
{
Toast.makeText(this, "On Location in High Accuracy", Toast.LENGTH_SHORT).show();
startActivityForResult(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS),2);
}else {
GetCurrentlocation();
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==2){
GPSStatus();
}
}
private void GetCurrentlocation() {
FusedLocationProviderClient mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
enable_location();
return;
}
mFusedLocationClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
#Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
// if we successfully get the location of the user then we will save the locatio into
//locally and go to the Main view
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(Constants.Lat,""+location.getLatitude());
editor.putString(Constants.Lon,""+location.getLongitude());
editor.commit();
startActivity(new Intent(SplashActivity.this, MainActivity.class));
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
finish();
}
else {
if(sharedPreferences.getString(Constants.Lat,"").equals("") || sharedPreferences.getString(Constants.Lon,"").equals("") ){
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(Constants.Lat,"33.738045");
editor.putString(Constants.Lon,"73.084488");
editor.commit();
}
startActivity(new Intent(SplashActivity.this, MainActivity.class));
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
finish();
}
}
});
}
private void enable_location() {
EnableLlocationFragment enable_llocationFragment = new EnableLlocationFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(R.anim.in_from_right, R.anim.out_to_left,R.anim.in_from_left,R.anim.out_to_right);
getSupportFragmentManager().popBackStackImmediate();
transaction.replace(R.id.splash, enable_llocationFragment).addToBackStack(null).commit();
}
}
I believe it must be something with my MainActivity that is causing the problem,
this is the main activity code
main activity:
public class MainActivity extends AppCompatActivity {
long mBackPressed;
public static SharedPreferences sharedPreferences;
public static String user_id;
public static String user_name;
public static String image;
public static String image1;
public static String birthday;
public static String about;
public static String purchased;
public static String token;
BaseApp baseApp;
LinearLayout llsearch;
DatabaseReference rootref;
AboutModels modelAbout;
public static String title="none";
EditText search;
public static MainActivity mainActivity;
private FragmentManager fragmentManager;
BottomNavigationView navigation;
int previousSelect = 0;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
HomeFragment homeFragment = new HomeFragment();
navigationItemSelected(0);
loadFrag(homeFragment, getString(R.string.menu_home), fragmentManager);
llsearch.setVisibility(View.VISIBLE);
return true;
case R.id.property:
PropertyFragment propertyFragment = new PropertyFragment();
navigationItemSelected(1);
loadFrag(propertyFragment, getString(R.string.menu_property), fragmentManager);
llsearch.setVisibility(View.GONE);
return true;
case R.id.favourite:
FavouriteFragment matchFragment = new FavouriteFragment();
navigationItemSelected(2);
loadFrag(matchFragment, getString(R.string.menu_favourite), fragmentManager);
llsearch.setVisibility(View.GONE);
return true;
case R.id.chat:
MessageFragment messageFragment = new MessageFragment();
navigationItemSelected(3);
loadFrag(messageFragment, getString(R.string.menu_chat), fragmentManager);
llsearch.setVisibility(View.GONE);
return true;
case R.id.user:
ProfileFragment profileFragment = new ProfileFragment();
navigationItemSelected(4);
loadFrag(profileFragment, getString(R.string.menu_profile), fragmentManager);
llsearch.setVisibility(View.GONE);
return true;
}
return false;
}
};
private BaseApp FirebaseInstanceId;
#RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout mAdViewLayout = findViewById(R.id.adView);
BannerAds.ShowBannerAds(getApplicationContext(), mAdViewLayout);
fragmentManager = getSupportFragmentManager();
llsearch = findViewById(R.id.llsearch);
baseApp = BaseApp.getInstance();
navigation = findViewById(R.id.navigation);
BottomNavigationViewHelper.disableShiftMode(navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
modelAbout = new AboutModels();
HomeFragment homeFragment = new HomeFragment();
loadFrag(homeFragment, getString(R.string.menu_home), fragmentManager);
mainActivity =this;
sharedPreferences = getSharedPreferences(Constants.pref_name, MODE_PRIVATE);
user_id = sharedPreferences.getString(Constants.uid, "null");
user_name = sharedPreferences.getString(Constants.f_name, "") + " " + sharedPreferences.getString(Constants.l_name, "");
image =sharedPreferences.getString(Constants.u_pic,"null");
image1 =sharedPreferences.getString("image1","null");
token=sharedPreferences.getString(Constants.device_token, FirebaseInstanceId.getInstance().getToken());
rootref= FirebaseDatabase.getInstance().getReference();
search = findViewById(R.id.search);
search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
String sSearch= search.getText().toString().trim();
if (TextUtils.isEmpty(sSearch)) {
Toast.makeText(MainActivity.this, "Column Can't be Empty", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(MainActivity.this, SearchActivity.class);
intent.putExtra("searchtext", sSearch);
startActivity(intent);
return true;
}
return false;
}
});
PackageInfo packageInfo = null;
try {
packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Constants.versionname=packageInfo.versionName;
}
#Override
protected void onStart() {
super.onStart();
if (baseApp.getIsLogin()) {
rootref.child("Users").child(user_id).child("token").setValue(token);
} else {
rootref.child("Users").child(user_id).child("token").setValue("null");
}
}
#Override
protected void onResume() {
super.onResume();
Check_version();
}
#Override
public void onBackPressed() {
int count = this.getSupportFragmentManager().getBackStackEntryCount();
if (count == 0) {
if (mBackPressed + 2000 > System.currentTimeMillis()) {
super.onBackPressed();
return;
} else {
clickDone();
}
} else {
super.onBackPressed();
}
}
public void clickDone() {
new AlertDialog.Builder(this)
.setIcon(R.mipmap.ic_launcher)
.setTitle(getString(R.string.app_name))
.setMessage("Are you sure you want to exit?")
.setPositiveButton("YES!", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
})
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.show();
}
public void Check_version(){
VersionChecker versionChecker = new VersionChecker(this);
versionChecker.execute();
}
public void loadFrag(Fragment f1, String name, FragmentManager fm) {
for (int i = 0; i < fm.getBackStackEntryCount(); ++i) {
fm.popBackStack();
}
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.Container, f1, name);
ft.commit();
}
public void navigationItemSelected(int position) {
previousSelect = position;
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.otacodes.goestate">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:name="com.otacodes.goestate.Constants.BaseApp"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="#style/AppTheme"
>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-1300058369369222~7049892454"/>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.otacodes.goestate.fileprovider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name="com.otacodes.goestate.Activity.SplashActivity"
android:screenOrientation="fullSensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.otacodes.goestate.Activity.LoginFormActivity"
android:screenOrientation="fullSensor"
android:theme="#style/Login_phone_A"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.RegisterActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.AllPropByCatActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.AllPropActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.AllPopularActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.AllPropByCityActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.SearchActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.MyPropertyActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.PropertyDetailActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.FilterSearchActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.PicklocationActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />
<activity
android:name="com.otacodes.goestate.Activity.MainActivity"
android:screenOrientation="portrait" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity
android:name="com.soundcloud.android.crop.CropImageActivity"
android:screenOrientation="portrait"
android:theme="#style/noActionBar"
/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/coloraccent" />
<service android:name="com.otacodes.goestate.Utils.NotificationReceive"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name="com.otacodes.goestate.Activity.AboutActivity" />
<activity android:name="com.otacodes.goestate.Activity.PrivacyActivity" />
<activity android:name="com.otacodes.goestate.Activity.BlockActivity" />
<activity android:name="com.otacodes.goestate.Activity.FullImageActivity" />
<activity android:name="com.otacodes.goestate.Activity.AddPropertyActivity" />
</application>
</manifest>
logcat
2022-01-05 01:50:49.624 4111-8222/? I/ExperimentPackageManage: Package com.google.android.os.statsd name not found! Using module version.
2022-01-05 01:50:49.626 4111-8222/? I/ExperimentPackageManage: Package com.google.android.os.statsd name not found! Using module version.
2022-01-05 01:50:49.631 4111-8222/? I/ayxc: updateFromConfigurations DeviceConfig for namespace virtualization_framework_native [CONTEXT service_id=204 ]
2022-01-05 01:50:49.572 3623-3623/? V/SettingsProvider: Notifying for 0: content://settings/config/app_standby/Phenotype_flags
2022-01-05 01:50:49.635 3623-3623/? V/SettingsProvider: Notifying for 0: content://settings/config/virtualization_framework_native/Phenotype_flags
2022-01-05 01:50:51.048 6662-6662/? D/BoundBrokerSvc: onUnbind: Intent { act=com.google.android.gms.feedback.internal.IFeedbackService cmp=com.google.android.gms/.chimera.GmsBoundBrokerService }
2022-01-05 01:50:52.610 1768-5915/? E/GnssHAL_GnssInterface: gnssSvStatusCb: b: input svInfo.flags is 8
2022-01-05 01:50:52.787 6662-6662/? D/BoundBrokerSvc: onUnbind: Intent { act=com.google.android.mdd.service.START cmp=com.google.android.gms/.chimera.GmsBoundBrokerService }
2022-01-05 01:50:53.138 4111-6600/? W/Nearby: Failed attempt #3 out of 3 for RestoreDeviceName [CONTEXT service_id=49 ]
java.lang.IllegalStateException: BluetoothAdapter not ready yet!
at aswl.d(:com.google.android.gms#214815031#21.48.15 (100700-414534850):2)
at aswj.run(:com.google.android.gms#214815031#21.48.15 (100700-414534850):0)
at cmvg.call(:com.google.android.gms#214815031#21.48.15 (100700-414534850):0)
at cmvl.a(:com.google.android.gms#214815031#21.48.15 (100700-414534850):2)
at cmvl.b(:com.google.android.gms#214815031#21.48.15 (100700-414534850):0)
at aswk.run(:com.google.android.gms#214815031#21.48.15 (100700-414534850):5)
at java.lang.Thread.run(Thread.java:919)
at xtk.run(:com.google.android.gms#214815031#21.48.15 (100700-414534850):5)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at xzm.run(:com.google.android.gms#214815031#21.48.15 (100700-414534850):0)
at java.lang.Thread.run(Thread.java:919)
2022-01-05 01:50:55.826 3623-3647/? E/memtrack: Couldn't load memtrack module
2022-01-05 01:50:55.826 6662-6662/? D/BoundBrokerSvc: onUnbind: Intent { act=com.google.android.gms.common.download.START cmp=com.google.android.gms/.chimera.GmsBoundBrokerService }
2022-01-05 01:50:55.826 3623-3647/? W/android.os.Debug: failed to get memory consumption info: -1
2022-01-05 01:50:55.869 6662-6662/? D/BoundBrokerSvc: onUnbind: Intent { act=com.google.android.gms.ocr.service.internal.START cmp=com.google.android.gms/.chimera.GmsInternalApiService }
2022-01-05 01:50:55.974 7623-7658/? I/Dialer: OmtpVvmCarrierCfgHlpr - OmtpEvent:CONFIG_STATUS_SMS_TIME_OUT
2022-01-05 01:50:55.976 7623-7623/? I/Dialer: RetryPolicy - discarding deferred status: configuration_state=4
2022-01-05 01:50:55.979 7623-7623/? I/Dialer: VvmTaskExecutor - no more tasks, stopping service if no task are added in 5000 millis
2022-01-05 01:50:55.980 7623-7623/? I/Dialer: VvmTaskReceiver - task received
2022-01-05 01:50:55.980 7623-7623/? I/Dialer: VvmTaskReceiver - TaskExecutor already running
2022-01-05 01:50:55.980 7623-7623/? I/Dialer: Task.createTask - create task:com.android.voicemail.impl.ActivationTask
2022-01-05 01:50:55.980 7623-7623/? I/Dialer: RetryPolicy - retry #1 for com.android.voicemail.impl.ActivationTask#d3f6d93 queued, executing in 5000
2022-01-05 01:50:55.981 7623-7623/? I/Dialer: VvmTaskExecutor - com.android.voicemail.impl.ActivationTask#d3f6d93 added
2022-01-05 01:50:55.981 7623-7623/? I/Dialer: VvmTaskExecutor - minimal wait time:5000
2022-01-05 01:50:55.981 7623-7623/? I/Dialer: VvmTaskExecutor - sleep for 5000 millis
2022-01-05 01:50:58.350 4111-8109/? E/GCM: Missing checkin config file
2022-01-05 01:50:58.350 4111-8109/? W/GCM: GCM FAILED TO INITIALIZE - missing checkin
2022-01-05 01:50:58.609 1768-5915/? E/GnssHAL_GnssInterface:
L_GnssInterface: gnssSvStatusCb: b: input svInfo.flags is 8
2022-01-05 01:51:00.984 7623-7658/? I/Dialer: VvmTaskExecutor - executing task com.android.voicemail.impl.ActivationTask#d3f6d93
2022-01-05 01:51:00.984 7623-7658/? I/Dialer: PreOMigrationHandler - ComponentInfo{com.android.phone/com.android.services.telephony.TelephonyConnectionService}, ***, UserHandle{0} already migrated
2022-01-05 01:51:01.021 7671-7685/? I/VoicemailNotifier: receivers for android.intent.action.PROVIDER_CHANGED :[]
2022-01-05 01:51:01.024 7623-7658/? I/Dialer: VvmActivationTask - VVM content provider configured - vvm_type_cvvm
2022-01-05 01:51:01.025 7623-7658/? I/Dialer: OmtpVvmCarrierCfgHlpr - OmtpEvent:CONFIG_ACTIVATING
2022-01-05 01:51:01.040 7671-7687/? I/VoicemailNotifier: receivers for android.intent.action.PROVIDER_CHANGED :[]
2022-01-05 01:51:01.047 3894-4110/? I/LocationAccessPolicy: Allowing com.android.dialer fine because it doesn't target API 29 yet. Please fix this app. Called from getServiceStateForSubscriber
2022-01-05 01:51:01.050 3894-4110/? I/LocationAccessPolicy: Allowing com.android.dialer coarse because it doesn't target API 29 yet. Please fix this app. Called from getServiceStateForSubscriber
Sorry because I can't comment, you should rebuild app, then open logcat and select error flag to view error log (default is verbose)
With only codes above, we can't help anything

When starting Android studio project, intent filter does not start from given page

I want the first LoginActivity.java page to open in my project, but AnasayfaActivity.java opens. I couldn't solve the problem. I use Android Studio. I am learning Android, and I would be glad if you help. I shared LoginActivity and AndroidManifest pages. When the application is opened for the first time, the Home Activity opens, when I go back, it goes to the LoginActivity.java page.
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.geziproject">
>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Geziproject">
<activity android:name=".AnasayfaActivity"/>
<activity android:name=".MainActivity2" />
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/Theme.Geziproject.NoActionBar">
</activity>
<activity android:name=".bos" />
<activity android:name=".kayitol" />
<activity android:name=".kullanicigiris" />
</application>
</manifest>
LoginActivity.java:
public class LoginActivity extends AppCompatActivity {
private Button signInButton;
private GoogleSignInClient mGoogleSignInClient;
private FirebaseAuth mAuth;
private Button signout;
Button btngiris;
Button btnkayit;
private EditText txtad;
private EditText txtemail;
private EditText txtsifre;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button btngiris = findViewById(R.id.btngiris);
Button btnkayit = findViewById(R.id.btnkayit);
txtemail = findViewById(R.id.txtemail);
txtsifre = findViewById(R.id.txtsifre);
signInButton = findViewById(R.id.signin);
mAuth = FirebaseAuth.getInstance();
// signout = findViewById(R.id.sign_out);
btngiris.setOnClickListener(v -> {
String email=txtemail.getText().toString();
String pwd= txtsifre.getText().toString();
if(email.isEmpty()){
txtemail.setError("Lütfen email giriniz");
txtemail.requestFocus();
}
else if(pwd.isEmpty()){
txtsifre.setError("Lütfen şifre giriniz");
txtsifre.requestFocus();
}
else if(email.isEmpty() && pwd.isEmpty())
{
Toast.makeText(LoginActivity.this,"Bu alanlar boş bırakılamaz",Toast.LENGTH_LONG).show();
}
else if(!(email.isEmpty() && pwd.isEmpty())){
mAuth.signInWithEmailAndPassword(email,pwd).addOnCompleteListener(LoginActivity.this, task -> {
if(!task.isSuccessful()){
Toast.makeText(LoginActivity.this,"Giriş başarısız ,tekrar deneyiniz",Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(LoginActivity.this,"Giriş başarılı",Toast.LENGTH_LONG).show();
txtemail.setText("");
txtsifre.setText("");
startActivity(new Intent(LoginActivity.this,AnasayfaActivity.class));
}
});
}
else{
Toast.makeText(LoginActivity.this,"Hata oluştu",Toast.LENGTH_LONG).show();
}
});
btnkayit.setOnClickListener(v -> {
Intent i= new Intent(LoginActivity.this,kayitol.class);
startActivity(i);
});
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken("1088981466528-8pkjha8350r2uniqg2425nv5itvgpvr7.apps.googleusercontent.com")
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
signInButton.setOnClickListener(v -> signIn());
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
startActivity(new Intent(LoginActivity.this, AnasayfaActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, 100);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
//handleSignInResult(task);
if (task.isSuccessful()) {
String s = "Google sign in Successful";
displayToast(s);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
Toast.makeText(getApplicationContext(), "giriş başarılı", Toast.LENGTH_LONG).show();
if (account != null) {
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
mAuth.signInWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Intent intent = new Intent(getApplicationContext(), AnasayfaActivity.class);
startActivity(intent);
}
}
});
}
} catch (ApiException e) {
e.printStackTrace();
}
}
}
}
private void displayToast(String s) {
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
}
}
As you set the launch activity in mainfest to LoginActivity, the app starts normally with the LoginActivity, but before the LoginActivity is resumend (i.e. shown on the screen) you added a condition in onCreate() method to launch the AnasayfaActivity as below:
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
startActivity(new Intent(LoginActivity.this, AnasayfaActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
If the user is not null (i.e. already logged-in), then the app goes directly to AnasayfaActivity activity without showing the LoginActivity to the user.
And the reason when you go back; the app go to the LoginActivity, because the LoginActivity is still in the back stack. If you want to remove the LoginActivity from the back stack then add Intent.FLAG_ACTIVITY_CLEAR_TOP to the intent:
startActivity(new Intent(LoginActivity.this, AnasayfaActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

Android broadcast reciever called but doesn't starts foreground service

I set up broadcast reciever for restarting my foreground service after reboot.
I have two devices and it works on Meizu M1 note (android 5.1) but doesn't work on Samsung A8 (android 9). Looking for reason in restrictions after Oreo and seems like it ok, but just in case https://developer.android.com/about/versions/oreo/background.html
On the second one broadcast reciever called, but service not started after reboot.
Service tracks location and uses startForeground() with Notification for correct work.
Also tried to add Worker to restart service after reboot, but seems like work missing after that.
Please, geve any suggestions why my reciever doesn't run service.
Thanks.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tracker">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=".ui.di.App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:isolatedProcess="true"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<receiver android:name="com.example.tracker.ui.broadcast.ServiceRestart">
<intent-filter>
<action android:name="restartService" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service
android:name="com.example.tracker.ui.service.TrackerService"
android:enabled="true" />
<service
android:name="com.example.tracker.ui.worker.RestartIntentService"
android:enabled="true" />
<activity android:name=".ui.screen.main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Reciever:
public class ServiceRestart extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.i("Broadcast Listened", "Service tried to stop");
Toast.makeText(context, "Broadcast: ServiceRestart launched " + intent.getAction(), Toast.LENGTH_LONG).show();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, TrackerService.class));
} else {
context.startService(new Intent(context, TrackerService.class));
}
}
}
Service:
public class TrackerService extends Service implements LocationListener {
public static final String TAG = "TrackerService";
private static final int PROCESS_ID = 1024;
private static final int INTERVAL = 120; //seconds
private ConnectivityManager connectivityManager;
private PeriodicWorkRequest workRequest;
private PeriodicWorkRequest restartTrackerRequest;
private DbFirebaseModel dbFirebaseModel = new DbFirebaseModel();
private ServiceHandler mServiceHandler;
private static final class ServiceHandler extends Handler {
public ServiceHandler(Looper looper) {
super(looper);
}
#Override
public void handleMessage(Message message) {
}
}
public void onCreate() {
super.onCreate();
HandlerThread mHandlerThread = new HandlerThread("TrackerService.HandlerThread");
mHandlerThread.start();
mServiceHandler = new ServiceHandler(mHandlerThread.getLooper());
}
public TrackerService() {
super();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
addNotificationAndStartForeground();
addWorkers();
mServiceHandler.post(() -> {
connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
runLocationTransfer();
});
Log.d(TAG, "===== SERVICE START");
return START_STICKY;
}
private void addWorkers() {
workRequest = new PeriodicWorkRequest.Builder(
FirebaseWorker.class, 15, TimeUnit.MINUTES, 2, TimeUnit.MINUTES)
.build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
FirebaseWorker.TAG,
ExistingPeriodicWorkPolicy.REPLACE,
workRequest);
restartTrackerRequest = new PeriodicWorkRequest.Builder(
TrackerRestartWorker.class, 15, TimeUnit.MINUTES, 2, TimeUnit.MINUTES
).build();
WorkManager.getInstance(this).enqueueUniquePeriodicWork(
TrackerRestartWorker.TAG,
ExistingPeriodicWorkPolicy.REPLACE,
restartTrackerRequest);
}
private void addNotificationAndStartForeground() {
String name = getString(R.string.app_name);
String description = "Service running...";
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
Notification.Builder notificationBuilder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
Integer.toString(PROCESS_ID), "Tracker", NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Notify me when location tracking");
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
notificationBuilder = new Notification.Builder(this, Integer.toString(PROCESS_ID));
notificationBuilder.setContentTitle(name)
.setContentText(description)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentIntent(pendingIntent);
notificationManager.notify(PROCESS_ID, notificationBuilder.build());
} else {
notificationBuilder = new Notification.Builder(this);
notificationBuilder.setContentTitle(name)
.setContentText(description)
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentIntent(pendingIntent);
}
startForeground(PROCESS_ID, notificationBuilder.build());
}
#Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "===== SERVICE STOP");
if (FirebaseAuth.getInstance().getCurrentUser() == null) {
WorkManager.getInstance(this).cancelWorkById(workRequest.getId());
WorkManager.getInstance(this).cancelWorkById(restartTrackerRequest.getId());
Log.d(TAG, "===== WORKERS STOP");
}
}
#Override
public void onTaskRemoved(Intent rootIntent) {
Log.d(TAG, "TASK REMOVED");
Toast.makeText(this, "LOCATION TASK REMOVED", Toast.LENGTH_SHORT).show();
super.onTaskRemoved(rootIntent);
}
private void runLocationTransfer() {
LocationRequest locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
locationRequest.setInterval(INTERVAL * 1000);
locationRequest.setFastestInterval(INTERVAL * 1000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(locationRequest);
LocationSettingsRequest locationSettingsRequest = builder.build();
SettingsClient settingsClient = LocationServices.getSettingsClient(this);
settingsClient.checkLocationSettings(locationSettingsRequest);
try {
getFusedLocationProviderClient(this).requestLocationUpdates(locationRequest, new LocationCallback() {
#Override
public void onLocationResult(LocationResult locationResult) {
onLocationChanged(locationResult.getLastLocation());
}
},
Looper.myLooper());
} catch (SecurityException e) {
e.printStackTrace();
}
}
#Override
public void onLocationChanged(#NonNull Location location) {
if (FirebaseAuth.getInstance().getCurrentUser() == null) {
stopSelf();
Log.d(TAG, "====== SERVICE STOPPED by itself");
} else if (connectivityManager.getActiveNetworkInfo() != null
&& connectivityManager.getActiveNetworkInfo().isConnected()) {
dbFirebaseModel.saveLocation(location);
// test using sound notifications
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(this, "LOCATION ------ LATITUDE: " + location.getLatitude() + " LONGITUDE: " + location.getLongitude(), Toast.LENGTH_SHORT).show();
} else {
saveToLocalStorage(location);
}
}
private void saveToLocalStorage(Location location) {
Hawk.init(this).build();
String userId = Objects.requireNonNull(
FirebaseAuth.getInstance().getCurrentUser()
).getUid();
LocationData locationData = new LocationData(userId, location);
long count = 0;
if (Hawk.count() > count) {
count = Hawk.count();
}
while (Hawk.contains(String.valueOf(count))) {
count++;
}
Hawk.put(String.valueOf(count), locationData);
Log.d(TAG, "HAWK /// Saved to local storage. COUNT = " + Hawk.count());
}
}
Following steps helped me solve it:
Remove and reinstall app
Change manifest according to this
<receiver android:name="com.foxminded.tracker.ui.broadcast.ServiceRestart"
android:exported="true"
android:enabled="true">
<intent-filter>
<action android:name="restartService" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Here added "android.intent.action.LOCKED_BOOT_COMPLETED" and android:exported="true" android:enabled="true"

Firebase Database not fetching data from Firebase Database Reference

Everything is working fine but DatabaseReference is not fetching data, it's like just ignoring my code to run and like my internet is not working please help i'm new here in this community below are my codes and images.
Previously it was working, but as i just changed some code to make only currentVersion >= vCode so that user can continue even if the value in database is < currentVersion but, after building it my app was not fetching data from firebase and the i tried to uninstall it, installed again from play store the older version it also was not fetching data please help. I don't know what wrong i did. Thus i am planning to install ParrotOS so maybe then it'll work but it's better to ask first from the experts
firebase database image
MainActivity.java
public class MainActivity extends AppCompatActivity {
TextView appName;
FirebaseUser firebaseUser;
String currentVersionName;
long currentVersionCode;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
appName = findViewById(R.id.appName);
currentVersionName = BuildConfig.VERSION_NAME;
currentVersionCode = BuildConfig.VERSION_CODE;
animateAppName();
netConn();
FirebaseAuth.getInstance();
}
public void applyScreenChange(){
String sharedPerfId = "MyAppPref";
SharedPreferences sharedPreferences = getSharedPreferences(sharedPerfId,0);
boolean isAdvertiserLoggedIn = sharedPreferences.getBoolean("isAdvertiserLoggedIn",false);
boolean isCreatorLoggedIn = sharedPreferences.getBoolean("isCreatorLoggedIn",false);
if (isAdvertiserLoggedIn){
skipSetupToAdvertiser();
}
else if (isCreatorLoggedIn){
skipSetupToCreator();
}
else {
newActivity();
}
}
public void animateAppName(){
appName.setTranslationY(-1000f);
appName.animate().translationYBy(1000f).setDuration(500);
}
public void netConn(){
ConnectivityManager connectivityManager = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
assert connectivityManager != null;
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if(networkInfo == null || !networkInfo.isConnected() || !networkInfo.isAvailable()){
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("No Internet Connection");
alertDialog.setMessage("Connect to Network and Then try again");
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Exit", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
MainActivity.super.onBackPressed();
}
});
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Retry", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
netConn();
}
});
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
}else {
// Check older version
// applyScreenChange();
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Version");
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
String vName = (String) snapshot.child("latestVersionName").getValue();
long vCode = (long) snapshot.child("latestVersionCode").getValue();
if (currentVersionName.equals(vName) && currentVersionCode >= vCode){
applyScreenChange();
// TODO: 16-08-2020 add condition to open app if version is higher
}else {
Toast.makeText(MainActivity.this, "Old Version", Toast.LENGTH_SHORT).show();
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("You're on Older Version");
alertDialog.setMessage("This Version is no more supported, Kindly update your App to Continue");
alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Exit", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
MainActivity.super.onBackPressed();
}
});
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Update", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
// startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.app_link))));
Toast.makeText(MainActivity.this, "Kindly Search Sponso on PlayStore and Update", Toast.LENGTH_SHORT).show();
finish();
}
});
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
}
public void newActivity(){
Intent intent = new Intent(MainActivity.this, AdvertiserCreatorChooser.class);
startActivity(intent);
finish();
}
public void skipSetupToAdvertiser(){
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser!=null) {
Intent intent = new Intent(MainActivity.this, AdvertiserHome.class);
startActivity(intent);
finish();
}else{
Intent intent = new Intent(MainActivity.this, AdvertiserLoginRegister.class);
startActivity(intent);
finish();
}
}
public void skipSetupToCreator(){
firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (firebaseUser!=null) {
Intent intent = new Intent(MainActivity.this, CreatorHome.class);
startActivity(intent);
finish();
}else {
Intent intent = new Intent(MainActivity.this, CreatorLoginRegister.class);
startActivity(intent);
finish();
}
}
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.webroose.sponso">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:allowBackup="true"
android:theme="#style/AppTheme">
<activity android:name=".Advertiser.AdvertiserCampaignUpdate"/>
<activity android:name=".Advertiser.ui.main.AdvertiserSettings" />
<activity android:name=".Creator.CreatorRecentlyChat" />
<activity android:name=".Advertiser.AdvertiserRecentlyChat" />
<activity android:name=".Advertiser.AdvertiserChatActivity" />
<activity android:name=".Creator.CreatorChatActivity" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="#string/app_id" />
<activity android:name=".Creator.CreatorUserDetails" />
<activity android:name=".Creator.CreatorList" />
<activity android:name=".Common.AboutUs" />
<activity
android:name=".AdvertiserHome"
android:label="#string/title_activity_advertiser_home"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".Advertiser.AdvertiserLoginRegister"
android:label="#string/title_activity_advertiser_login_register"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".Common.PrivacyPolicy" />
<activity android:name=".Common.ChangePassword" />
<activity android:name=".Creator.CreatorSettings" />
<activity android:name=".Common.ChangeEmail" />
<activity android:name=".Advertiser.AdvertiserUserDetails" />
<activity android:name=".Advertiser.AdvertiserList" />
<activity
android:name=".CreatorHome"
android:label="#string/title_activity_creator_home"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".Creator.CreatorLoginRegister"
android:label="#string/title_activity_creator_login_register"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".AdvertiserCreatorChooser" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
dependency
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.google.firebase:firebase-database:19.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.google.firebase:firebase-database:19.4.0'
implementation 'com.firebaseui:firebase-ui-database:6.2.0'
implementation 'com.google.android.gms:play-services-ads:19.3.0'
implementation 'com.android.support:multidex:2.0.0'
implementation 'com.google.firebase:firebase-analytics:17.5.0'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.facebook.android:audience-network-sdk:5.10.1'
}
Change
DatabaseReference databaseReference =FirebaseDatabase.getInstance().getReference("Version");
To
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("Version");
And the actual problem was with Firebase Database
Check below image with firebase database

SERVICE_VERSION_UPDATE_REQUIRED

Actually I'm building an application which requires user's location. But I'm getting SERVICE_VERSION_UPDATE_REQUIRED error. Following are my MainActivity.java and AndroidManifest.xml files:
MainActivity.java
TextView lat, lon;
private static final String TAG = MainActivity.class.getSimpleName();
private FusedLocationProviderApi locationProvider = LocationServices.FusedLocationApi;
private GoogleApiClient googleApiClient;
private LocationRequest locationRequest;
private double latitude, longitude;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lat = (TextView) findViewById(R.id.lat);
lon = (TextView) findViewById(R.id.lon);
if (googleApiClient == null) {
googleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
locationRequest = new LocationRequest();
locationRequest.setInterval(10000);
locationRequest.setFastestInterval(1000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
#Override
public void onConnected(#Nullable Bundle bundle) {
requestLocationUpdates();
}
private void requestLocationUpdates() {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
#Override
public void onConnectionSuspended(int i) {
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
Log.d(TAG, connectionResult.toString());
}
#Override
public void onLocationChanged(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
lat.setText("Latitude: " + String.valueOf(latitude));
lon.setText("Longitude: " + String.valueOf(longitude));
}
#Override
protected void onStart() {
super.onStart();
googleApiClient.connect();
}
#Override
protected void onResume() {
super.onResume();
if (googleApiClient.isConnected()) {
requestLocationUpdates();
}
}
#Override
protected void onPause() {
super.onPause();
LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
}
#Override
protected void onStop() {
super.onStop();
googleApiClient.disconnect();
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.harshil.location">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_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">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is what logcat says:
D/MainActivity: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
So, How to get through this problem?
I solved my problem by changing following line [in build.gradle] from:
compile 'com.google.android.gms:play-services:10.0.1'
to:
compile 'com.google.android.gms:play-services:9.8.0'
So, the problem is I am using higher version of Google Play Service for development than that installed on my device or emulator.
I came to my solution as follow:
1. I checked to update Google Play Service on my device but it says it is up-to-date.
2. I checked in App Manager to see the version of it, and I came to know that it is actually at 9.8.77. So I changed play-service version from 10.0.1 to 9.8.0.
Now, I am out of this problem.
Thank you.
Download the the google play store in your mobile and check it .for me i was not installed google play store in my mobile now i installed google play store ,its working fine.

Categories

Resources