This Android SDK integration guide uses Fragments.
1. Extend your Main activity from the FragmentActivity class and implement PushEventListener interface:
public class PushFragmentActivity extends FragmentActivity implements PushEventListener
2. In onCreate function call PushFragment.init(this);
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Init Pushwoosh fragment PushFragment.init(this);
3. In onNewIntent function call PushFragment.onNewIntent(this, intent);
@Override public void onNewIntent(Intent intent) { super.onNewIntent(intent); //Check if we've got new intent with a push notification PushFragment.onNewIntent(this, intent); }
4. Implement callbacks as per PushEventListener interface
public void doOnRegistered(String registrationId) { mGeneralStatus.setText(registrationId); } public void doOnRegisteredError(String errorId) { mGeneralStatus.setText(errorId); } public void doOnUnregistered(final String message) { mGeneralStatus.setText(message); } public void doOnUnregisteredError(String errorId) { mGeneralStatus.setText(errorId); } public void doOnMessageReceive(String message) { mGeneralStatus.setText(message); }
5. In AndroidManifest.xml manifest add the following lines under application tag. The GCM Project Number is a number, but make sure you prefix it with the letter "A".
Example:
<meta-data android:name="PW_APPID" android:value="4F0C807E51EC77.93591449" /> <meta-data android:name="PW_PROJECT_ID" android:value="A60756016005" />
Where:
PW_APPID
is the Pushwoosh Application Code and PW_PROJECT_ID
– is the Project Number you receive from Google Locate your Project Number prefixed with A.
(See more: http://developer.android.com/guide/google/gcm/index.html and http://developer.android.com/guide/google/gcm/gs.html)
<activity android:name="PushFragmentActivity" android:launchMode="singleTop" android:label="@string/app_name"> <intent-filter> <action android:name="PACKAGE_NAME.MESSAGE"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>
7. Add the following changes in your AndroidManifest.xml under manifest tag. Replace PACKAGE_NAME with the package name for your application.
GET_ACCOUNTS permission: GCM requires a Google account if you target Androids lower than 4.0.4