0

I'm working on an android nearby application, and I'm trying to subscribe() to nearby messages via the nearby messages API of Google, I managed to connect to the googleApiClient but when subscribing, I get a TOO_MANY_PENDING_INTENT error.

here is my code:

    private void subscribe() {
    if (mSubscribed) {
        Log.i(TAG, "Already subscribed.");
        return;
    }

    SubscribeOptions options = new SubscribeOptions.Builder()
            .setStrategy(Strategy.BLE_ONLY)
            .build();


    Nearby.Messages.subscribe(mGoogleApiClient, getPendingIntent(), options)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Subscribed successfully.");
                        startService(getBackgroundSubscribeServiceIntent());
                    } else {
                        Log.e(TAG, "Operation failed. Error: " +
                                NearbyMessagesStatusCodes.getStatusCodeString(
                                        status.getStatusCode()));
                    }
                }
            });
}

And my manifest :

<uses-feature
    android:name="android.hardware.bluetooth_le"
    android:required="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- This is required for the scan library. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
    android:allowBackup="true"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <meta-data
        android:name="com.google.android.nearby.messages.API_KEY"
        android:value="AIzaSyB6hlT5939qLK2HORZoeiHx2vytqKrtFHA" />

    <activity android:name=".uid.Main2Activity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

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

    <service
        android:name="org.physical_web.uid.BackgroundSubscribeIntentService"
        android:exported="false" /> 
...

Does someone have an idea about this problem please ? Thank you :)

Aymane Bo
  • 59
  • 2
  • 11
  • Does the code ever set `mSubscribed` to true? If not, `getPendingIntent()` will be called each time the `subscribe()` method shown is called. – davidgyoung May 29 '16 at 11:35
  • yes, in my onCreate() methode : if (savedInstanceState != null) mSubscribed = savedInstanceState.getBoolean(KEY_SUBSCRIBED, false); I just copy pasted the code from the google developpers web site. – Aymane Bo May 30 '16 at 07:04
  • 1
    What does the code for getPendingIntent() look like? Make sure to always use the same intent (incl. the same request code, but extras can be different). Also rebooting should clear everything up, try that and see if you get the error again. – Joe Farfel Jun 02 '16 at 23:32

1 Answers1

0

Make sure that your package name what you have given in manifest file and build.gradle are same and same should be used while getting the API key