انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
راه اندازی سرویس (Service) از طریق کلیک روی نوتیفیکیشن (برنامه نویسی اندروید)

راه اندازی سرویس (Service) از طریق کلیک روی نوتیفیکیشن (برنامه نویسی اندروید)

#8
دوستان خوشبختانه حل شد  

از بردکاست رسیور استفاده کردم .
کد ها رو میزارم شاید بدرد بخوره :

متد آنکریت اکتیویتی اصلی :

کد پی‌اچ‌پی:
@Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        
setContentView(R.layout.activity_main);



        
NotificationManager notificationManager = (NotificationManagergetApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
        
Intent intent = new Intent(getApplicationContext(), BroadcastReceiver.class);
        
PendingIntent contentIntent PendingIntent.getBroadcast(getApplicationContext(), 0intent0);
        
Notification notification = new Notification(R.mipmap.ic_launcher"developers.mehran.FIRST"System.currentTimeMillis());
        
notification.setLatestEventInfo(getApplicationContext(), "title first""first"contentIntent);
        
notification.flags Notification.FLAG_AUTO_CANCEL;
        
notificationManager.notify(0notification);


    } 

کلاس رسیور :

کد پی‌اچ‌پی:
public class BroadcastReceiver extends android.content.BroadcastReceiver {

    @
Override
    
public void onReceive(Context contextIntent intent) {


        
NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(context)
                .
setSmallIcon(R.mipmap.ic_launcher// notification icon
                
.setContentTitle("Notification!"// title for notification
                
.setContentText("kelidestan.com"// message for notification
                
.setAutoCancel(false); // clear notification after click
        
Intent i = new Intent(contextMainActivity.class);
        
PendingIntent pi PendingIntent.getActivity(context,0,i,Intent.FLAG_ACTIVITY_NEW_TASK);
        
mBuilder.setContentIntent(pi);
        
NotificationManager mNotificationManager =
                (
NotificationManagercontext.getSystemService(Context.NOTIFICATION_SERVICE);
        
mNotificationManager.notify(0mBuilder.build());


    }


اینم تگ رسیور داخل منی فست :

کد پی‌اچ‌پی:
<receiver android:name=".BroadcastReceiver">
            <
intent-filter>
                <
action android:name="developers.mehran.FIRST"/>
            </
intent-filter>
        </
receiver
پاسخ
 سپاس شده توسط admin ، شماره مجازی امارات


پیام‌های این موضوع
RE: راه اندازی سرویس (Service) از طریق کلیک روی نوتیفیکیشن (برنامه نویسی اندروید) - توسط mehran_ab - ۱۳۹۴/۰۸/۲۹, ۰۷:۱۹ ب.ظ

پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان