+我的SetAction值在OnReceive方法上成功比较,但我想在该动作上播放一首歌,但我无法帮助我 +我的BroadcastReceiver类正在关注
package com.Audio.audioplayer;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat.Builder;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;
public class MyReceiver extends BroadcastReceiver implements Listenercalling{
Listenercalling ls;
private static final String TAG = "waaaawoooooooooOOOOOOjnjkhdfku";
public void onReceive(Context context, Intent intent) {
//btnplay=(ImageButton)btnplay;
final String action=intent.getAction();
if(action.equals("btnplay"))
{
ls=new PlayerAudioActivity();
}
// if(AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)){
Log.d(TAG, ""+action);
// Bundle extras=intent.getExtras();
// String ieString=extras.getString("Locale");
// try{
// final int Appwidgid=extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,AppWidgetManager.INVALID_APPWIDGET_ID);
// if(Appwidgid!=AppWidgetManager.INVALID_APPWIDGET_ID)
// {
// this.onDeleted(context, new int[] { Appwidgid });
// }
// else {
// onReceive(context, intent);
// }
// context.startService(new Intent(context,PlayerAudioActivity.class));
// Log.i(TAG,"Starting Service ConnectivityListener");
// }catch(Exception e){
// Log.e(TAG,e.toString());
// }
// }
}
private void onDeleted(Context context, int[] is) {
// TODO Auto-generated method stub
}
}
My Notifiaction方法遵循以下功能AudiopllayerActivity
private void Notify(String notificationTitle, String notificationMessage)
{
String ns=Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager=(NotificationManager)getSystemService(ns);
@SuppressWarnings("deprecation")
Notification notification=new Notification(R.drawable.bg,"Time",System.currentTimeMillis());
RemoteViews notificationView=new RemoteViews(getPackageName(),R.layout.main);
Intent notificationIntent=new Intent(this,PlayerAudioActivity.class);
PendingIntent pendingNotificationIntent=PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentView=notificationView;
notification.flags|=Notification.FLAG_NO_CLEAR;
//supposed button call intent
Intent switchIntent=new Intent(this,MyReceiver.class);
switchIntent.setAction("btnplay");
PendingIntent pendingIntent=PendingIntent.getBroadcast(this, 0, switchIntent, 0);
notificationView.setOnClickPendingIntent(R.id.btnPrevious, pendingIntent);
// Builder mBuilder = new NotificationCompat.Builder(this);
//
// mBuilder
// .setContentTitle(notificationTitle )
// .setContentText(notificationMessage)
// .setSmallIcon(R.drawable.btn_play)
// .setContentIntent(pendingIntent)
// .addAction(R.drawable.btn_previous,"", pendingIntent)
// .addAction(R.drawable.btn_pause,"", pendingIntent)
// .addAction(R.drawable.btn_next,"", pendingIntent).build();
// btnprevious.setOnClickListener(new View.OnClickListener() {
//
// @Override
// public void onClick(View v) {
// if(currentSongIndex>0)
// {
// playSong(currentSongIndex-1);
// currentSongIndex=currentSongIndex-1;
// }
// else
// {
// playSong(songsList.size());
// currentSongIndex=(songsList.size()-1);
// }
//
// }
// });
//
notificationManager.notify(1, notification);
}