emperatorsoftware
سه شنبه 20 مرداد 1394, 23:38 عصر
سلام دوستان
من یه برنامه نوشتم که به یه سری شماره حساس باشه وقتی از اونا اس ام اس میاد نوتیفیکشن بده و بوق بزنه
حالا اینم کدی که نوشتم اما روی دستگاه اندرویدی که اجرا میکنم خبری از نوتیفیکشن نیست و برنامه رو از Splash اجرا میکنه نه از INboxSMSactivity که توو کد نوشتم
ممنون میشم کمکم کنید بدجور گیر کردم:گریه:
public class SMSReceiver extends BroadcastReceiver {
DBAdapter s_db;
List<SensorsmsProvider> s_etes;
SensorsmsProvider s_ete;
public static int SIMPLE_NOTIFICATION_ID = 0;
String MText;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle extras = intent.getExtras();
if (extras != null) {
Object[] pdus = (Object[])extras.get("pdus");
if (pdus.length < 1)
return; // Invalid SMS. Not sure that it's possible.
StringBuilder sb = new StringBuilder();
String sender = null;
for (int i = 0; i < pdus.length; i++) {
SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (sender == null) sender = message.getOriginatingAddress();
String text = message.getMessageBody();
long buf = message.getTimestampMillis();
Toast.makeText(context, buf + "", Toast.LENGTH_LONG).show();
MText = text;
if (text != null) sb.append(text);
}
s_db = new DBAdapter(context);
s_db.open();
s_etes = s_db.getContactFromSensorsmsByActiveOrNot(1);
for(int i = 0 ; i < s_etes.size() ; i++ ){
s_ete = s_etes.get(i);
if (sender != null && sender.equals("+98" + s_ete.getNumber())) {
// Process our sms...
Toast.makeText(context, "SMS ", Toast.LENGTH_LONG).show();
int icon = R.drawable.ic_launcher;
CharSequence tickerText = sender + "D";
long when = System.currentTimeMillis();
CharSequence contentTitle = sender + "";
CharSequence contentText = MText;
NotificationManager mNotificationManager=
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERV ICE);
Intent notificationIntent = new Intent(context, InboxSMSActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notifyDetails = new Notification(icon, tickerText , when);
mNotificationManager.notify(SIMPLE_NOTIFICATION_ID , notifyDetails);
if(s_ete.getAlarm() == 1){
final MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.light_switch_on);
mediaPlayer.start();
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mediaPlayer.release();
}
});
}
if(s_ete.getAbort() == 1){
abortBroadcast();
}
}
}
return;
}
}
// ...
}
و اینم مانیفسست برنامه
<receiver android:name=".SMSReceiver" >
<intent-filter android:priority="2300" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
من یه برنامه نوشتم که به یه سری شماره حساس باشه وقتی از اونا اس ام اس میاد نوتیفیکشن بده و بوق بزنه
حالا اینم کدی که نوشتم اما روی دستگاه اندرویدی که اجرا میکنم خبری از نوتیفیکشن نیست و برنامه رو از Splash اجرا میکنه نه از INboxSMSactivity که توو کد نوشتم
ممنون میشم کمکم کنید بدجور گیر کردم:گریه:
public class SMSReceiver extends BroadcastReceiver {
DBAdapter s_db;
List<SensorsmsProvider> s_etes;
SensorsmsProvider s_ete;
public static int SIMPLE_NOTIFICATION_ID = 0;
String MText;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle extras = intent.getExtras();
if (extras != null) {
Object[] pdus = (Object[])extras.get("pdus");
if (pdus.length < 1)
return; // Invalid SMS. Not sure that it's possible.
StringBuilder sb = new StringBuilder();
String sender = null;
for (int i = 0; i < pdus.length; i++) {
SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (sender == null) sender = message.getOriginatingAddress();
String text = message.getMessageBody();
long buf = message.getTimestampMillis();
Toast.makeText(context, buf + "", Toast.LENGTH_LONG).show();
MText = text;
if (text != null) sb.append(text);
}
s_db = new DBAdapter(context);
s_db.open();
s_etes = s_db.getContactFromSensorsmsByActiveOrNot(1);
for(int i = 0 ; i < s_etes.size() ; i++ ){
s_ete = s_etes.get(i);
if (sender != null && sender.equals("+98" + s_ete.getNumber())) {
// Process our sms...
Toast.makeText(context, "SMS ", Toast.LENGTH_LONG).show();
int icon = R.drawable.ic_launcher;
CharSequence tickerText = sender + "D";
long when = System.currentTimeMillis();
CharSequence contentTitle = sender + "";
CharSequence contentText = MText;
NotificationManager mNotificationManager=
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERV ICE);
Intent notificationIntent = new Intent(context, InboxSMSActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
Notification notifyDetails = new Notification(icon, tickerText , when);
mNotificationManager.notify(SIMPLE_NOTIFICATION_ID , notifyDetails);
if(s_ete.getAlarm() == 1){
final MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.light_switch_on);
mediaPlayer.start();
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mediaPlayer.release();
}
});
}
if(s_ete.getAbort() == 1){
abortBroadcast();
}
}
}
return;
}
}
// ...
}
و اینم مانیفسست برنامه
<receiver android:name=".SMSReceiver" >
<intent-filter android:priority="2300" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>