I am developing an android application,In my application using Urban Airship for Push notifica开发者_高级运维tion.It is working fine,I want to if i click on "Notification On" in UI,I will receive Notification to my device,when i click "Notification OFF" in my UI,I will not receive notification to my device.How to implement the code in Urban Airship?How is possible?
Thanks
to enable it
PushManager.enablePush();
and to disable it
PushManager.disablePush();
In your button Click, put this code:
final Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
final ComponentName cn = new ComponentName(
"com.urbanairship.airmail",
"com.urbanairship.airmail.MainListActivity");
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Followed by this in your manifest file put this in your <application Tag>
:
android:name=".QuadDealsPushReceiver"
Create a QuadDealsPushReceiver.class and put this code:
package com.fsp.quaddeals;
import com.urbanairship.push.APIDReceiver;
import com.urbanairship.push.AirMail;
import com.urbanairship.push.PushReceiver;
import android.app.Application;
import android.content.Intent;
import android.util.Log;
public class QuadDealsPushReceiver extends Application {
public void onCreate(){
AirMail am = AirMail.getInstance();
am.acceptPush(this, new PushReceiver() {
@Override
public void onReceive(String message, String payload){
Log.d("push", "Got message '" + message +"' and payload '" + payload + "'");
}
@Override
public void onClick(String message, String payload){
Log.d("push", "User clicked the notification, got message and payload: "
+ message + ", " + payload);
/* In this example, we fire up our MainActivity class when the
* user clicks the Status Bar Notification. Note that we *must*
* use the flag Intent.FLAG_ACTIVITY_NEW_TASK to start a new
* activity because this callback is fired from within a
* BroadcastReceiver.
**/
Intent intent = new Intent("android.intent.action.MAIN");
intent.setClass(QuadDealsPushReceiver.this, SplashMain.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
QuadDealsPushReceiver.this.startActivity(intent);
}
});
am.setAPIDReceiver(this, new APIDReceiver() {
@Override
public void onReceive(String apid, boolean valid){
if(valid){
Log.d("push", "Got apid: " + apid);
} else {
Log.d("push", "Application registration invalid!"+ apid);
}
}
@Override
public void onAirMailInstallRefusal() {
QuadMain.register = false;
Log.d("push", "AirMail Install Refused!");
}
});
}
}
For further clarification use this link:
Help for Push notification
精彩评论