java将意向值从通知传递给活动类
/** Updates the notification. */
void updateNotification(String text) {
Log.i(TAG, text);
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
new Intent(getApplicationContext(), MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(getApplicationContext(), "nikhil", text, pi);
notificationManager.notify(NOTIFICATION_ID, notification);
}
/**
* Configures service as a foreground service. A foreground service is a service that's doing
* something the user is actively aware of (such as playing music), and must appear to the
* user as a notification. That's why we create the notification here.
*/
void setUpAsForeground(String text) {
/* Intent launchIntent;
String myType="one";
launchIntent = new Intent(getBaseContext(), MainActivity.class);
launchIntent.putExtra("checkme", myType);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), -1, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
*/
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
new Intent(getApplicationContext(), MainActivity.class),
PendingIntent.FLAG_UPDATE_CURRENT);
notification = new Notification();
notification.tickerText = text;
notification.icon = R.drawable.ic_stat_playing;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.setLatestEventInfo(getApplicationContext(), "nikhil", text, pi);
startForeground(NOTIFICATION_ID, notification);
}
以上代码来自我的服务类,我只需要将一个字符串传递给MainActivity类。我从Stackover flow中尝试了很多,但没有任何效果。请帮忙
# 1 楼答案
# 2 楼答案
试试这种方法,希望这能帮助你解决问题强>
# 3 楼答案
用这个