Simulating gcm notification from console

In this post I will show only example of using gcm notification broadcasting from console. I assume You have working gcm methods in your project.
You must change also in manifest two things.
1. In gcm receiver You must remove SEND
2. In permission list paste permission to send gcms.

<receiver
android:name="com.example.android.gcm.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND"//<--REMOVE, COPY TO CLIPBOARD
>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>

<!--PERMISSION LIST-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.SEND" />//<--PASTE PERMISSION HERE

Below pattern “how-to” and example.

PATTERN
//adb shell am broadcast -a <Intent-Name> -n <Package>/<Receiver-Name-with-leading-dot> <Extras>

My app needs some params (–es is kind of argument [key-value]).

COMMAND
adb shell am broadcast -a com.google.android.c2dm.intent.RECEIVE -c com.example.android.debug -n com.example.android.google.debug/com.example.android.gcm.GcmBroadcastReceiver --es "key1" "abc" --es "key2" "def"

Notepad++ with regex, re-using match variables

Here is an simple example how to use regex in notepad++ with reusing selected match variables.

For example we have special code for simulating gcm notifications. We would like to see it in pretty style.
To achieve this we must to move all elements with minus to the new lines. How to do it? Here is the solution.

We have this string:
adb shell am broadcast -a com.google.android.c2dm.intent.RECEIVE -c com.example.android.debug -n com.example.android.google.debug/com.example.android.gcm.GcmBroadcastReceiver --es "aaa" "123" --es "mmm" "bla bla bla" --es "sss" "321" --es "from" "111" --es "type" "yesterday" --es "collapse_key" "do_not_collapse"

By using bellow command in notepad++:

Searching text:

\-[a-z]{0,2}\s

Replace with:

\n($0)

We get the quite pretty result:

adb shell am broadcast
-a com.google.android.c2dm.intent.RECEIVE
-c com.example.android.debug
-n com.example.android.google.debug/com.example.android.gcm.GcmBroadcastReceiver
--es "aaa" "123"
--es "mmm" "bla bla bla"
--es "sss" "321"
--es "from" "111"
--es "type" "yesterday"
--es "collapse_key" "do_not_collapse"

GCM notification with custom sound – shorter version (part)

Here is a short example how to create notification with default stuff but different sound:

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("message"))
.setContentText("message")
.setAutoCancel(true)
.setSound(soundUri)
.setDefaults(NotificationCompat.DEFAULT_ALL ^ NotificationCompat.DEFAULT_SOUND);

The most important part is here:

.setDefaults(NotificationCompat.DEFAULT_ALL ^ NotificationCompat.DEFAULT_SOUND)

Symbol

^

says “except”, so the last part would say “give me default notification except sound setting”