Back to project page terapush-android-sdk.
The source code is released under:
Your use is subject to the Terms & Conditions at https://app.terapush.com/docs/End-User-License-Agreement.html
If you think the Android project terapush-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.terapush.samples; /*from w w w.ja v a 2s . c o m*/ import java.util.HashMap; import java.util.Map; import com.terapush.android.TeraPush; import com.terapush.samples.R; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { /** * Some configuration details, this is we set up our GCM and TeraPush configuration */ public static final String YOUR_SENDER_ID = "<GCM SENDER ID>"; public static final String YOUR_COMPANY_NAME = "<TERAPUSH COMPANY NAME>"; public static final String YOUR_COMPANY_KEY = "<TERAPUSH COMPANY KEY>"; public static final String YOUR_APP_VERSION = "<APPLICATION VERSION>"; public Button register = null; public Button unregister = null; public TeraPush tp; @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); /** * To receive parameters from push notification when you application is * in foreground. */ if (intent.getExtras() != null && intent.getExtras().getString("LandingPage") != null) { Context context = getApplicationContext(); Toast toast = Toast.makeText(context, intent.getExtras().getString("LandingPage"), Toast.LENGTH_SHORT); toast.show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /** * Initializing TeraPush */ tp = new TeraPush(getApplicationContext(), YOUR_SENDER_ID, YOUR_COMPANY_NAME, YOUR_COMPANY_KEY, YOUR_APP_VERSION, R.drawable.ic_launcher); /** * Register push on button click */ register = (Button) findViewById(R.id.button1); register.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { tp.registerDevice(); } }); /** * Unregister push on button click */ unregister = (Button) findViewById(R.id.button2); unregister.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { tp.unRegisterDevice(); } }); /** * Use setTags method to provide custom parameters to your server For * example: * * * Map<String, String> tags = new HashMap<String, String>(); * * Set up the tags map * * tags.put("tag1", "0"); * tags.put("tag2", "1"); * tags.put("tag3", "0"); * * Save the map * tp.setTags(tags); * * Commit to TeraPush server * tp.registerDevice(); */ } public void onResume() { super.onResume(); Intent intent = getIntent(); Context context = getApplicationContext(); /** * To receive parameters from push notification when you application is * in background or not running. */ if (getIntent() != null) { if (intent.getExtras() != null && intent.getExtras().getString("LandingPage") != null) { Toast toast = Toast.makeText(context, intent.getExtras() .getString("LandingPage"), Toast.LENGTH_SHORT); toast.show(); } } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }