Son Forum Aktiviteleri

2
Tümünü Gör

Notificationdan uygulamaya komut

Merhaba bir radyo uygulamasında notification olusturdum. player sayfasından ileri geri play pause yapınca notificatication degisiyor radyo ismi çalan sarkı.

tersi şekilde notificationdan ileri geri yapınca çalışıyor ama uygulamada radyo ismi guncellensin istiyorum. bunu nasıl yapabilirim.? 

8 yıl 6 ay önce yanıtladın

Notificationdan uygulamaya komut

06 Nisan 2016 tarihinde cevaplandı

    private void setUpNotification(String title) {

        CharSequence status = MyPreference.getInstance(getApplicationContext()).getLastAlbumURLTitle();

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

 

        Intent intentNotif = new Intent(this, MainActivity.class);

        intentNotif.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intentNotif, PendingIntent.FLAG_UPDATE_CURRENT);

 

        mRemoteViews = new RemoteViews(getPackageName(), R.layout.notification);

        mRemoteViews.setTextViewText(R.id.status_text, status);

        Bitmap mBitmap = ImageLoader.getInstance(getApplicationContext())

                .getBitmapForNotifiction(myPreference.getLastAlbumURLImage());

        if (mBitmap != null) {

            mRemoteViews.setBitmap(R.id.status_icon, "setImageBitmap", mBitmap);

        } else {

            mRemoteViews.setImageViewResource(R.id.status_icon, R.drawable.music_icon);

        }

 

        Intent playPauseIntent = new Intent("send_to_service_data");

        playPauseIntent.putExtra("activityMessage", 29);

        PendingIntent pendingPlayPauseIntent = PendingIntent.getBroadcast(getApplicationContext(), 1000,

                playPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        mRemoteViews.setOnClickPendingIntent(R.id.btnPlayPause, pendingPlayPauseIntent);

        

        Intent NextIntent = new Intent("send_to_service_data2");

        NextIntent.putExtra("activityMessage", 51);

        PendingIntent NextPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1000,

                NextIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        mRemoteViews.setOnClickPendingIntent(R.id.btnIleri, NextPendingIntent);

        Intent PrevIntent = new Intent("send_to_service_data3");

        PrevIntent.putExtra("activityMessage", 52);

        PendingIntent PrevPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 1000, PrevIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        mRemoteViews.setOnClickPendingIntent(R.id.btnGeri, PrevPendingIntent);

        boyle devam ediyor diger komutlar icin bundan sonrada  işlevler var

 

private void updateNext() {

       

            fetchDataFromServer();

            if (radyo == null) {

                Toast.makeText(this, "Empty radyo", 1).show();

            } else if (position == radyo.size() - 1) {

                Log.d("position", position + "!Next");

            } else if (radyo.size() != 1) {

                position++;

                Log.d("position", new StringBuilder(String.valueOf(position)).toString());

                MyPreference.getInstance(getApplicationContext()).setLastAlbumURLTitle( radyo.get(position).getTitle());

                MyPreference.getInstance(getApplicationContext()).setLastAlbumURL( radyo.get(position).getLink());

                MyPreference.getInstance(getApplicationContext()).setLastAlbumURLImage(radyo.get(position).getImage());

                playNextSong(MyPreference.getInstance(this).getLastAlbumURL());

                updatePlayPause(R.drawable.btnn_pause);

                if (radyo.get(position).getImage().length() > 0) {

                    Bitmap mBitmap = ImageLoader.getInstance(getApplicationContext()).getBitmapForNotifiction(myPreference.getLastAlbumURLImage());

                    if (mBitmap != null) {

                        mRemoteViews.setBitmap(R.id.status_icon, "setImageBitmap", mBitmap);

                    } else {

                        mRemoteViews.setImageViewResource(R.id.status_icon, R.drawable.music_icon);

                    }

                }

            }

        }

ve handler

private Handler mHandler=new Handler(){

            @Override

            public void handleMessage(android.os.Message msg) {

                if(radyo!=null  && radyo.size()>0){

 

                    if(radyo.get(0).getLink().startsWith(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Radiobox")){

                        Intent intent = new Intent();

                        intent.putExtra("position", MyPreference.getInstance(getApplicationContext()).getLastAlbumItemPos());

                        intent.putExtra("isPlayAuto", true);

                        intent.putExtra("fromWhere", "recording");

                        intent.putExtra("list_data", radyo);

                            

                    }else{

                        //TODO Open the 

                        Intent intent = new Intent();

                        intent.putExtra("fromWhere", "station");

                        intent.putExtra("isPlayAuto", true);

                        intent.putExtra("position", MyPreference.getInstance(getApplicationContext()).getLastAlbumItemPos());

                        intent.putExtra("list_data", radyo);

 

                    }

                }else{

 

 

 

 

 

private class RequestDataBroadCast extends BroadcastReceiver {

 

        @Override

        public void onReceive(Context context, Intent intent) {

            if (intent.getAction().equalsIgnoreCase("sleeper_time_broadcast")) {

                if (SleepCounter.timer_finished) {

                    BASS.BASS_StreamFree(chan);

                    stopForeground(true);

                }

            } else if (intent.getAction().equalsIgnoreCase("send_to_service_data1")) {

                BASS.BASS_StreamFree(chan);

                stopForeground(true);

            } else {

 

                int position = intent.getIntExtra("activityMessage", 0);

                switch (position) {

 

                case 21:

                    // TODO For playing a new song

                    Logger.error("Play Song..." + myPreference.getLastAlbumURL());

                    fileToPlay = myPreference.getLastAlbumURLTitle() + " - " + "playing";

                    Log.i("DREG", " Url ="+fileToPlay);

                    playNextSong(myPreference.getLastAlbumURL());

                    break;

                case 22:

                    isRec = intent.getExtras().getBoolean("recStatus");

                    break;

 

                case 23:

                    DoMeta();

                    break;

                case 24:

                

                    BASS.BASS_Pause();

//                    

                    updateNotification("pause");

                    isMusicPlaying = false;

                    

                    break;