-1

Below code is working fine upto marshmallow but it not working in from 7.0

I create Brocast receiver for to fetch location every 6 sec.

MainActivity.java

 private PendingIntent getPendingIntent() {

        Intent intent = new Intent(this, LocationUpdatesBroadcastReceiver.class);
        intent.setAction(LocationUpdatesBroadcastReceiver.ACTION_PROCESS_UPDATES);
        return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

 public void requestLocationUpdates(View view) {
        try {
             mFusedLocationClient.requestLocationUpdates(mLocationRequest, getPendingIntent());

        } catch (SecurityException e) {
            Utils.setRequestingLocationUpdates(this, false);
            Log.e("requestLocationUpdates","     "+e.toString());
            e.printStackTrace();
        }
    }

LocationUpdatesBroadcastReceiver.class

This is my BrocadcastReceiver class

public class LocationUpdatesBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "LUBroadcastReceiver";
static final String ACTION_PROCESS_UPDATES =
        "com.google.android.gms.location.sample.locationupdatespendingintent.action" +
                ".PROCESS_UPDATES";

   @Override
public void onReceive(Context context, Intent intent) {


    if (intent != null) {


        final String action = intent.getAction();

        Log.d("showthepackgesss","*****     "+action +" \n"+ACTION_PROCESS_UPDATES );


        if (ACTION_PROCESS_UPDATES.equals(action)) {
            LocationResult result = LocationResult.extractResult(intent);
            if (result != null) {
                List<Location> locations = result.getLocations();
                Utils.setLocationUpdatesResult(context, locations);
                Utils.sendNotification(context, Utils.getLocationResultTitle(context, locations));
                Log.i(TAG, Utils.getLocationUpdatesResult(context));
            }
        }
    }else {
        Toast.makeText(context,"No Intent found checkit",Toast.LENGTH_SHORT).show();
    }
}
}

My Manifestfile.xml

Here is my manifestfiles

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

    <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:roundIcon="@mipmap/ic_launcher_round"
        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>


        <service android:name=".LocationUpdatesIntentService"
                 android:exported="false"></service>

        <receiver android:name=".LocationUpdatesBroadcastReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="com.example.cbdc.locationupdates_background.LocationUpdatesBroadcastReceiver.ACTION_PROCESS_UPDATES" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

if any one know please help me.....Thanks in advance!!!!!!

demo
  • 672
  • 3
  • 9
  • 34

1 Answers1

0

You need to add support for runtime permissions, introduced in API 23.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • Actually, it is an answer: runtime permissions support is needed. The provided code does not handle it at all. The code catches a `SecurityException` and just logs an error. – Larry Schiefer Jan 31 '18 at 14:58