nasr
شنبه 24 مرداد 1394, 16:05 عصر
سلام
من یک Activity دارم با نام LoginActivity
توی این Activity یک متد نوشته ام به این صورت
public void showNotification() {
PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, SmsRecive.class), 0);
Resources r = getResources();
Notification notification = new NotificationCompat.Builder(this)
.setTicker(r.getString(R.string.notification_title ))
.setSmallIcon(android.R.drawable.ic_menu_report_im age)
.setContentTitle(r.getString(R.string.notification _title))
.setContentText(r.getString(R.string.notification_ text))
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
حالا مثلا روی OnClick یک دکمه در همین Activity وقتی اجرا می کنم به خوبی اجرا میشه و مشکلی ندارم
حالا می خوام همین متد را در یک Class دیگه استفاده کنم
یه کلاس دارم با نام IncommingSMS که وقتی پیامک میاد یک سری کارهایی انجام میده
من به این روش از این متد اسفاده می کنم ولی ظاهرا درست نیستچ
LoginActivity laginAct = new LoginActivity();
laginAct.showNotification()
سوال من اینه که چطور از این showNotification که در LoginActivity است در بقیه برنامه هم استفاده کنم؟
ممنون
من یک Activity دارم با نام LoginActivity
توی این Activity یک متد نوشته ام به این صورت
public void showNotification() {
PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, SmsRecive.class), 0);
Resources r = getResources();
Notification notification = new NotificationCompat.Builder(this)
.setTicker(r.getString(R.string.notification_title ))
.setSmallIcon(android.R.drawable.ic_menu_report_im age)
.setContentTitle(r.getString(R.string.notification _title))
.setContentText(r.getString(R.string.notification_ text))
.setContentIntent(pi)
.setAutoCancel(true)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, notification);
}
حالا مثلا روی OnClick یک دکمه در همین Activity وقتی اجرا می کنم به خوبی اجرا میشه و مشکلی ندارم
حالا می خوام همین متد را در یک Class دیگه استفاده کنم
یه کلاس دارم با نام IncommingSMS که وقتی پیامک میاد یک سری کارهایی انجام میده
من به این روش از این متد اسفاده می کنم ولی ظاهرا درست نیستچ
LoginActivity laginAct = new LoginActivity();
laginAct.showNotification()
سوال من اینه که چطور از این showNotification که در LoginActivity است در بقیه برنامه هم استفاده کنم؟
ممنون