привет, как говорится в названии. Мне нужно отправить действие для вещания получателя из уведомления ... я сделал много исследований, чтобы найти способ исправить это. Но я не получаю действие на приемник вещания, пожалуйста, помогите мне немного и извините за любые неудобства, которые я сделал ..!.Уведомление отправляет намерение передать вещание
УВЕДОМЛЕНИЕ КОД:
@Override
public void onPause() {
Intent resultIntent = new Intent(getApplicationContext(), AndroidPlayer.class);
resultIntent.setAction(Intent.ACTION_MAIN);
resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent playIntent = new Intent("ovh.smonitor.androidplayer.ACTION_PLAY");
PendingIntent playPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, playIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//PendingIntent playPendingIntent = PendingIntent.getBroadcast(this, 0, playIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent stopIntent = new Intent("ovh.smonitor.androidplayer.ACTION_STOP");
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//PendingIntent stopPendingIntent = PendingIntent.getActivity(this, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder mBuilder = new Notification.Builder(this)
.setContentTitle(getResources().getText(R.string.app_name))
.setContentText("Press to return.")
.setSmallIcon(R.drawable.ic_radio_white)
.setPriority(Notification.PRIORITY_HIGH)
.addAction(R.drawable.ic_play_arrow_white, "Play", playPendingIntent)
.addAction(R.drawable.ic_pause_white, "Stop", stopPendingIntent)
.setContentIntent(resultPendingIntent)
.setOngoing(true)
.setAutoCancel(true);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, mBuilder.build());
if (this.isFinishing())
notificationManager.cancel(0);
super.onPause();
}
радиовещательный приемник:
package ovh.smonitor.androidplayer;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
public class RemoteControlReceiver extends BroadcastReceiver {
MediaPlayer mPlayer = new MediaPlayer();
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("ovh.smonitor.androidplayer.ACTION_PLAY")) {
System.out.println("ACTION PLAY !.");
} else if (intent.getAction().equals("ovh.smonitor.androidplayer.ACTION_STOP")) {
if (mPlayer.isPlaying()) {
mPlayer.stop();
}
}
}
}
МАНИФЕСТ (ВНУТРИ ПРИМЕНЕНИЕ):
<receiver
android:name=".RemoteControlReceiver"
android:enabled="true">
<intent-filter>
<action android:name="ovh.smonitor.androidplayer.ACTION_PLAY" />
<action android:name="ovh.smonitor.androidplayer.ACTION_STOP" />
</intent-filter>
</receiver>
любые предложения, почему я не получаю никакого ответа на мой приемник. thnx для вашего времени!.
Thnx за ваше время .. уже найти способ получить намерение от трансляции .. моя проблема .., что я не могу использовать объект MediaPlayer уже играл на основной деятельности .. поэтому я может остановить его и воспроизвести его из уведомления .. i ge t, что медиаплеер имеет значение NULL ... поэтому я не могу остановить его с помощью панели уведомлений только с основным приложением для работы. Можете ли вы мне помочь? –
Я думаю, вы можете использовать ** динамический приемник ** вместо ** статического приемника **: создать свой приемник в своем основном действии, тогда вы можете получить объект медиапланера, когда получили некоторые действия. И поскольку ваша последняя проблема была решена, вам лучше обновить свой вопрос, чтобы другие знали вашу текущую проблему. – starkshang