我正在开发一个 Android 应用程序,并且我已经注册了 PushBots 通知服务,并且我成功地在我的手机上接收到通知。
但是当我点击通知时没有任何反应..
我想要的是当用户点击通知时我想打开我的 MainActivity。
我创建了 3 个 java 文件:
1)MainActivity.java
2)MyApplication.java
3)customPushReceiver.java
我的问题是我应该在哪里编写 MainActivity 将在单击通知时开始的代码?我应该写什么代码?
这是我所有的三个班级代码。
1) MainActivity.java 代码-
package com.example.ptest2;
import com.pushbots.push.Pushbots;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private static final Context Context = null;
private String SENDER_ID="My_SENDER_ID";
private String PUSHBOTS_APPLICATION_ID="MY_Application_ID";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
2) MyApplication.java 代码-
package com.example.ptest2;
import android.widget.Toast;
import com.pushbots.push.Pushbots;
public class MyApplication extends android.app.Application
{
private String SENDER_ID="MY_SENDER_ID";
private String PUSHBOTS_APPLICATION_ID="MY_Application_ID";
@Override
public void onCreate()
{
super.onCreate();
Pushbots.init(this, SENDER_ID,PUSHBOTS_APPLICATION_ID);
}
}
3) customPushReceiver.java 代码-
package com.example.ptest2;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.BroadcastReceiver;
import java.awt.font.TextAttribute;
import java.util.HashMap;
import com.pushbots.push.Pushbots;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Context;
import android.content.Intent;
public class customPushReceiver extends BroadcastReceiver
{
private static final String TAG = "customPushReceiver";
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Your time is up", Toast.LENGTH_LONG).show();
Vibrator v;
v=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(3000);
}
}
onReceive 方法正在成功运行..
我的问题是我应该在哪里编写 MainActivity 将在单击通知时开始的代码?我应该写什么代码?