کلیدستان

نسخه‌ی کامل: راه اندازی سرویس (Service) از طریق کلیک روی نوتیفیکیشن (برنامه نویسی اندروید)
شما در حال مشاهده نسخه آرشیو هستید. برای مشاهده نسخه کامل کلیک کنید.
سلام دوستان

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

چجوری از اینتنت (Intent) باید استفاده کنم ؟ 
(۱۳۹۴/۰۸/۲۸, ۱۱:۰۱ ب.ظ)'mehran_ab' نوشته: [ -> ]سلام دوستان

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

چجوری از اینتنت باید استفاده کنم ؟ 
 

اینجوری؟

کد پی‌اچ‌پی:
Intent in = new Intent(this UrServ.class)
PendingIntent pe PendingIntent.getService(this in in.FLAG_ACTIVITY_NEW_TASK)
NotiName.setContentIntent(pe

نمیدونستم چجوری تو یه بلاک مخصوص کد بنویسمش Big Grin
خیلی ممنون 

برای نوشتن به صورت کد اون بالا روی php بزن و توی اون بنویس .
یه سوال دیگه:
اگر بخوایم توی نوتیفیکیشن یه پروگرس بار مثلا برای دانلود نشون بدیم باید چیکار کنیم ؟ 
(۱۳۹۴/۰۸/۲۸, ۱۱:۳۸ ب.ظ)'dmo' نوشته: [ -> ]
(۱۳۹۴/۰۸/۲۸, ۱۱:۰۱ ب.ظ)'mehran_ab' نوشته: [ -> ]سلام دوستان

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

چجوری از اینتنت باید استفاده کنم ؟ 



 
اینجوری؟
کد پی‌اچ‌پی:
Intent in = new Intent(this UrServ.class)
PendingIntent pe PendingIntent.getService(this in in.FLAG_ACTIVITY_NEW_TASK)
NotiName.setContentIntent(pe
نمیدونستم چجوری تو یه بلاک مخصوص کد بنویسمش Big Grin
 

 

متاسفانه کار نمیکنه  

این فقط برای رفتن به یه اکتیویتی کار میکنه
 
(۱۳۹۴/۰۸/۲۸, ۱۱:۰۱ ب.ظ)'mehran_ab' نوشته: [ -> ]سلام دوستان

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

چجوری از اینتنت (Intent) باید استفاده کنم ؟ 

 

سلام.
لینک های زیر را ببینید :

http://stackoverflow.com/questions/23651...tion-click

http://stackoverflow.com/questions/64223...tification

(۱۳۹۴/۰۸/۲۹, ۱۲:۱۸ ب.ظ)'admin' نوشته: [ -> ]
(۱۳۹۴/۰۸/۲۸, ۱۱:۰۱ ب.ظ)'mehran_ab' نوشته: [ -> ]سلام دوستان

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

چجوری از اینتنت (Intent) باید استفاده کنم ؟ 
 

سلام.
لینک های زیر را ببینید :

http://stackoverflow.com/questions/23651...tion-click

http://stackoverflow.com/questions/64223...tification


 

واقعا ممنون ادمین جان منم این ها رو دیده بودم اما نمیدونم چجوری ازشون استفاده کنم 

اینجوری استفاده کردم اما بازم کار نمیکنه :

کد پی‌اچ‌پی:
NotificationCompat.Builder mBuilder =   new NotificationCompat.Builder(this)
        .
setSmallIcon(R.mipmap.ic_launcher// notification icon
        
.setContentTitle(title// title for notification
        
.setContentText(text// message for notification
        
.setAutoCancel(false); // clear notification after click
Intent intent = new Intent(thisMainActivity.class);
PendingIntent pi PendingIntent.getService(this0intentIntent.FLAG_ACTIVITY_NEW_TASK);
mBuilder.setContentIntent(pi);
NotificationManager mNotificationManager =
        (
NotificationManagergetSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0mBuilder.build()); 
دوستان خوشبختانه حل شد  

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

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

کد پی‌اچ‌پی:
@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