public class SmsReciver extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; public String newmessage;//static @Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdus.length; i++){
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
for(SmsMessage message : messages) {
newmessage = message.getMessageBody();
Intent newIntent = new Intent(context,AirFluxActivity.class);
// 在Service中启动Activity,必须设置如下标志
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newIntent);
}
}
}
}
}
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED"; public String newmessage;//static @Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdus.length; i++){
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
for(SmsMessage message : messages) {
newmessage = message.getMessageBody();
Intent newIntent = new Intent(context,AirFluxActivity.class);
// 在Service中启动Activity,必须设置如下标志
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(newIntent);
}
}
}
}
}
解决方案 »
- 如何用post将xml文件发到网络上
- android 调用摄像头出错
- Android图表引擎AChartEngine 横坐标修改刻度标签
- 现在有没有可以反编译出android应用中的本地代码的工具?
- 如何学习安卓?
- 找一篇基于android的移动学习终端的开发的外文
- 关于运行时出现的stopped unexpected的问题,,格鲁求救
- Andriod黑屏问题
- 一个很有用的webServer,怎么把它编译成android能适应的动态库
- android studio混淆打包过程中遇到的问题,求大神!!
- Log.d("",""+i)这样调试程序需要考虑多线程吗?
- ExpandableListView中组item的默认icon如何让更改?
不行的时候Log中有什么信息啊
06-09 09:45:09.471: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/notification_sound
06-09 09:45:09.502: ERROR/MediaPlayer(52): Unable to to create media player
06-09 09:45:09.471: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/notification_sound
06-09 09:45:09.502: ERROR/MediaPlayer(52): Unable to to create media player
06-09 09:45:09.471: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/notification_sound
06-09 09:45:09.502: ERROR/MediaPlayer(52): Unable to to create media player
06-09 09:45:09.471: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/notification_sound
06-09 09:45:09.502: ERROR/MediaPlayer(52): Unable to to create media player
06-09 09:45:09.502: ERROR/MediaPlayer(52): Unable to to create media player
06-09 09:45:09.502: ERROR/MediaPlayer(52): Unable to to create media player
06-09 09:45:11.116: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/notification_sound
06-09 09:45:11.116: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/notification_sound
06-09 09:45:11.168: ERROR/MediaPlayer(52): Unable to to create media player
06-09 09:45:11.168: ERROR/MediaPlayer(52): Unable to to create media player
06-09 09:45:28.156: ERROR/ActivityThread(100): Failed to find provider info for android.server.checkin
06-09 09:45:28.156: ERROR/ActivityThread(100): Failed to find provider info for android.server.checkin
06-09 09:45:29.276: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/ringtone
06-09 09:45:29.299: ERROR/MediaPlayer(100): Unable to to create media player
06-09 09:45:29.299: ERROR/RingtoneManager(100): Failed to open ringtone content://settings/system/ringtone
06-09 09:45:29.276: ERROR/MediaPlayerService(31): Couldn't open fd for content://settings/system/ringtone
06-09 09:45:29.299: ERROR/MediaPlayer(100): Unable to to create media player
06-09 09:45:29.299: ERROR/RingtoneManager(100): Failed to open ringtone content://settings/system/ringtone
06-09 09:47:01.207: WARN/ActivityManager(52): Activity pause timeout for HistoryRecord{44d9e9f8 com.android.phone/.InCallScreen}
06-09 09:47:02.226: WARN/InputManagerService(52): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44e20d30
06-09 09:47:02.226: WARN/InputManagerService(52): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44e20d30
06-09 09:47:02.816: WARN/ActivityManager(52): Activity pause timeout for HistoryRecord{44e79f58 com.android.phone/.InCallScreen}
06-09 09:47:02.816: WARN/ActivityManager(52): Activity pause timeout for HistoryRecord{44e79f58 com.android.phone/.InCallScreen}
06-09 09:47:02.816: WARN/ActivityManager(52): Activity pause timeout for HistoryRecord{44e79f58 com.android.phone/.InCallScreen}
06-09 09:47:02.816: WARN/ActivityManager(52): Activity pause timeout for HistoryRecord{44e79f58 com.android.phone/.InCallScreen}
06-09 09:47:02.816: WARN/ActivityManager(52): Activity pause timeout for HistoryRecord{44e79f58 com.android.phone/.InCallScreen}
06-09 09:47:02.816: WARN/ActivityManager(52): Activity pause timeout for HistoryRecord{44e79f58 com.android.phone/.InCallScreen}
06-09 09:47:02.816: WARN/ActivityManager(52): Activity pause timeout for HistoryRecord{44e79f58 com.android.phone/.InCallScreen}
这些是警告日志
可以在收到广播时,通过状态栏提示,启动Acitivityfor(SmsMessage message : messages) {
newmessage = message.getMessageBody();
Intent newIntent = new Intent(context,AirFluxActivity.class);
PendintIntent pi=PendingIntent.getActivity(context,0,newIntent,0);
Notification myNoti=new Notification();
NotificationManager noti=(NotificationManager)context.getSystemService(Service.NOTIFICATION_SERVICE);
myNoti.icon=R.drawable.icon;
myNoti.tickerText="启动activity";
myNoti.setLatestEventInfo(context,"service","启动activity",pi);
noti.notify(0,myNoti);
}楼主试试吧!
解决的办法就是在广播里面向handler发送一个消息,在handler里面去打开一个界面。
A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active. This has important repercussions to what you can do in an onReceive(Context, Intent) implementation: anything that requires asynchronous operation is not available, because you will need to return from the function to handle the asynchronous operation, but at that point the BroadcastReceiver is no longer active and thus the system is free to kill its process before the asynchronous operation completes. In particular, you may not show a dialog or bind to a service from within a BroadcastReceiver. For the former, you should instead use the NotificationManager API. For the latter, you can use Context.startService() to send a command to the service. (最后一句是介意您最好使用一个服务去启动一个界面,因为广播在处理onReceive函数后就会消毁)