待定意图不起作用

时间:2015-09-10 10:14:03

标签: android push-notification android-pendingintent

我知道我问的问题是重复的。但我尝试过各种各样的事情。我想要的是,当我点击通知时,会调用MainActivity类。我的代码是,

private void sendNotification(String msg) 
{
    Log.d(TAG, "Preparing to send notification...: " + msg);
    int requestID = (int) System.currentTimeMillis();
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent notificationIntent = new Intent(this,MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

    PendingIntent contentIntent = PendingIntent.getActivity(this, requestID,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                                            .setSmallIcon(R.drawable.icon)
                                            .setContentTitle("Hashtag")
                                            .setContentText(msg)
                                            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                                            .setContentIntent(contentIntent);
    mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
    mBuilder.setLights(Color.RED, 3000, 3000);
    mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
    mBuilder.setAutoCancel(true);

    mNotificationManager.notify((int)Calendar.getInstance().getTimeInMillis(), mBuilder.build());
    Log.e("NEW NOTIFICATION ID IS --- ", String.valueOf((int)Calendar.getInstance().getTimeInMillis()));
    Log.d(TAG, "Notification sent successfully.");
}

我的MainActivity Class如下,

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    loadUrl(launchUrl);
    Toast.makeText(getApplicationContext(), "this is my Toast!!!",Toast.LENGTH_LONG).show();
}

我想叫吐司。请人们帮帮我!!这一整天都在杀了我.. !!!

0 个答案:

没有答案