Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从通知栏上,给工人阶级打电话_Java_Android_Notificationmanager - Fatal编程技术网

Java 从通知栏上,给工人阶级打电话

Java 从通知栏上,给工人阶级打电话,java,android,notificationmanager,Java,Android,Notificationmanager,我正在开发一个在线广播应用程序。应用程序在后台工作。当我单击NotificationManager时,radioclass再次开始工作。我想呼叫正在运行的radioclass。我该怎么办 player = MediaPlayer.create(this, Uri.parse("http://...../playlist.m3u8")); player.setAudioStreamType(AudioManager.STREAM_MUSIC); player

我正在开发一个在线广播应用程序。应用程序在后台工作。当我单击NotificationManager时,radioclass再次开始工作。我想呼叫正在运行的radioclass。我该怎么办

player = MediaPlayer.create(this, Uri.parse("http://...../playlist.m3u8"));
        player.setAudioStreamType(AudioManager.STREAM_MUSIC);
            player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer player) {

                }
            });
            player.start();



final int notificationID = 1234;
        String msg = "mesajjj";
        Log.d(TAG, "Preparing to update notification...: " + msg);

        NotificationManager mNotificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);



        Intent intent = new Intent(this, RadioClass.class);
//这节课又开始了。但RadioClass已经开始运行了。我应该给正在运行的RadioClass打电话

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK);


    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.logotam)
                .setContentTitle("Test FM")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg);

        mBuilder.setContentIntent(pendingIntent);
        mNotificationManager.notify(notificationID, mBuilder.build());

如果要返回到当前正在运行的相同活动,可以按如下方式执行:

 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
在AndroidManifest.xml上添加以下标记:

<activity
........
    android:launchMode="singleTop" >
........
</activity>
通过这些修改,您可以确保您的活动在任何给定时间只有一个实例。在activity类上,还可以重写onNewIntent方法:

    @Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

}

此方法将处理对活动的所有其他调用。

Perfect!非常感谢你。