How to set up the BroadCast receiver in Android?

Greetings

Is there any resource for creating the broadcast receiver? At the beginning I though backendless include a broadcast receiver and then after sending a notification from the console it will be display automatically, but then after some search here I found this http://support.backendless.com/t/push-notification-targeting-specific-devices there is an example of a broadcast receiver also found this https://github.com/Backendless/Android-SDK/blob/master/src/com/backendless/push/BackendlessBroadcastReceiver.java but neither of both has a tutorial structure so Im struggling with this.

Is there any resource where I can learn to create a BroadcastReceiver for Backendless?

Hi Erick,

Scroll down to the bottom of this page (see the section Push Notifications):
http://backendless.com/documentation/messaging/android/messaging_requirements.htm

Regards,
Mark

Hello Mark

Thanks for the quick answer, but I did that!

The problem is I keep getting “Message scheduled” but nothing happens, neither in the console, neither in the phone.

Like this other describe: http://support.backendless.com/t/message-not-published

And also I have done this twice http://backendless.com/documentation/messaging/android/messaging_push_notification_setup_androi.htm

I dont undestand, by registering the broadcast receiver in the manifest plus having backendless in my gradle I should get notifications? I dont have to do a broadcast receiver?

On the server side (using Backendless console), you need to enter your Google API key.

On the client side you need to configure Broadcast receiver.

Can you tell me what message headers you send along with the message? Or even better, can you show the code you use to send out your push notification?

I have enter my API key twice, and same result with both.

Im sending, publisher id and subtopic blank, in header Im sending the title indicated in the docs here https://backendless.com/documentation/messaging/android/messaging_publish_push_notifications.htm, like this “android-content-title”:“value” and in message just some text like “msg”. Look I made a video to show you:

https://nimbus.everhelper.me/client/notes/share/video/312130/Kn2DVUVsUqv0SBVD7A6bQLNvnPahfnoD/none/p3l1445462645841/video.webw

Ok so I have to configure the broadcast receiver, How? Allready declared it in the manifest.xml

Couple of things from your video:

    Your device does not show up as registered. Do you make this call in your application?: http://backendless.com/documentation/messaging/android/messaging_device_registration.htm Make sure to put all android headers (not just one as you do it now).
Regards, Mark

Mark

    Yes I did it, and yes it is registered, I didnt click in the device tab in video cause there are some ids arround there, but look https://box.everhelper.me/attachment/312139/RCgIWb40gypLXqUV2fOGq2n7NeoD0Spq/430501-1srNAvhHVJbp5aNy/screen.jpeg And, nope didnt worked :( use all the headers, using the "key":"value", "key":"value" format
Hey sorry, for being such a rookie, Im really greatfull for all your help, I wish we can solve this, push notification is the last thing I need for my app.

Could you post here your project manifest file?

<?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="cl.cutiko.diadelpicoapp">

    &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.GET_ACCOUNTS&quot;/&gt;
    &lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot;/&gt;
    &lt;uses-permission android:name=&quot;com.google.android.c2dm.permission.RECEIVE&quot;/&gt;
    &lt;uses-permission android:name=&quot;cl.cutiko.diadelpicoapp.permission.C2D_MESSAGE&quot;/&gt;
    &lt;permission android:name=&quot;cl.cutiko.diadelpicoapp.permission.C2D_MESSAGE&quot; android:protectionLevel=&quot;signature&quot;/&gt;


    <application
        android:name=".GlobalApplication_"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        tools:replace="android:icon">

        &lt;receiver android:name=&quot;com.backendless.push.BackendlessBroadcastReceiver&quot; android:permission=&quot;com.google.android.c2dm.permission.SEND&quot;&gt;
            &lt;intent-filter&gt;
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
                &lt;category android:name=&quot;cl.cutiko.diadelpicoapp&quot;/&gt;
            &lt;/intent-filter&gt;
        &lt;/receiver&gt;

        <activity
            android:name=".ui.LoginActivity_"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            &lt;intent-filter&gt;
                <action android:name="android.intent.action.MAIN" />

                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;/intent-filter&gt;
        </activity>

        &lt;service android:name=&quot;com.backendless.AndroidService&quot; /&gt;

        <activity
            android:name=".ui.ProfileActivity_"
            android:label="@string/title_activity_profile"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>
        <activity
            android:name=".ui.AddDiligenceActivity_"
            android:label="@string/title_activity_add_diligence"
            android:theme="@style/AppTheme.NoActionBar" >
        </activity>

        <meta-data
            android:name="DATABASE"
            android:value="diligence.db" />
        <meta-data
            android:name="VERSION"
            android:value="1" />
        <meta-data
            android:name="QUERY_LOG"
            android:value="true" />
        <meta-data
            android:name="DOMAIN_PACKAGE_NAME"
            android:value="cl.cutiko.diadelpicoapp" />


    </application>

&lt;/manifest&gt;

Looks good. I have done all I could and am out of ideas… someone from the dev team will be following up with you. Until then, could you try this:

    Open Code Generation in Backendless console Select "Sample chat" in the Messaging box Download the app and compile it. Run it on 2 different devices (or device an emulator)
The app uses push notifications and we know it works. If it still does not work for you, the problem must be with the Google API key config on the Manage > App Settings screen.

Mark

I cant import the project to Android Studio, wizard run as expected but when I try to compile I get a tons of errors, I try both, Intellij files and Eclipse files.

So lets try to see if the problem is with the google config then:

    First I choose to create an "API key", like in this screenschot http://nimb.ws/70LGmJ Then I choose the "Server key" like here http://nimb.ws/tYf8K5 After that Im using that key for the console setting in Backendless http://nimb.ws/zYIpKe Also this is what Im using in the registration (.java files in the android project) http://nimb.ws/0EtreW
Am I doing something wrong in Google?

Looks good.

The generated project would open in IntelliJ IDEA. Have you thought/tried creating a new project in Android Studio and simply import the generated code and manifest?

Also, something else to check in Google Developers Console:

    Click API and then click Cloud Messaging for Android: http://monosnap.com/image/7YBmKwjs69lUiqrDHi9mOqvQOz2sK7 Make sure the API is enabled: http://monosnap.com/image/56uD1IVB8B4VhvAD308QCYA9O22861
Cheers, Mark

Well, if we ever meet, please remind me to buy you like a dozen of beers, enable the value, and instantly got the notification!

Wow! Im going to write this in the setup doc, so if any one else have the same problem can fix it, you should also try to add the reference.

Thank you!

I am not sure I can handle a dozen of beers…, but thank you! )) If you help us spread the word about Backendless and get other developers to use the service, it will be very much appreciated too :slight_smile:

Count on me! Actually Im gonna do it right now on a couple of FB groups :slight_smile:

Hi, i have message:
MY APP: Error de Servidor - No receivers for action com.google.android.c2dm.intent.REGISTRATION.
help me, no register device!!. :frowning:

Please show what your AndroidManifest looks like.

Version:0.9
StartHTML:-1
EndHTML:-1
StartFragment:0000000111
EndFragment:0000008777

&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
&lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot;/&gt;
&lt;uses-permission android:name=&quot;com.google.android.c2dm.permission.RECEIVE&quot;/&gt;
&lt;uses-permission android:name=&quot;[PACKAGE NAME].permission.C2D_MESSAGE&quot;/&gt;
<permission android:name="[PACKAGE NAME].permission.C2D_MESSAGE"
    android:protectionLevel="signature"/>

<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"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        &lt;intent-filter&gt;
            <action android:name="android.intent.action.MAIN" />

            &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
        &lt;/intent-filter&gt;
    </activity>
    <receiver android:name="com.backendless.push.BackendlessBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        &lt;intent-filter&gt;
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            &lt;category android:name=&quot;[PACKAGE NAME]&quot;/&gt;
        &lt;/intent-filter&gt;
    &lt;/receiver&gt;
    &lt;service android:name=&quot;com.backendless.push.BackendlessPushService&quot; /&gt;
</application>

</manifest>

Version:0.9
StartHTML:-1
EndHTML:-1
StartFragment:0000000111
EndFragment:0000005010

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();
    }
});
Backendless.initApp(this,"XXXX","XXXX","v1");
Messaging.DEVICE_ID = "EMULADOR";
Backendless.Messaging.registerDevice("XXX","default", new AsyncCallback&lt;Void&gt;(){
    @Override
    public void handleResponse(Void Response){
        Toast.makeText(MainActivity.this,"Dispositivo Registrado",Toast.LENGTH_SHORT).show();
        Log.i("MY APP","Dispositivo Registrado");
    }
    @Override
    public void handleFault(BackendlessFault fault){
        Toast.makeText(MainActivity.this,fault.getMessage(),Toast.LENGTH_SHORT).show();
        Log.i("MY APP","Error de Servidor - "+fault.getMessage());
    }
});

}

What version of Android do you target? I do not think “com.google.android.c2dm.intent.REGISTRATION” is used anymore.