我正在尝试编写一个试图接收SMS消息并处理它们的简单应用程序.我已经按照了几个教程,但是我无处可去,当我向模拟器发送短信时,Intent似乎永远不会被解雇.
这是我的意图:
package com.neocodenetworks.smsfwd;
import android.content.*;
import android.os.Bundle;
import android.telephony.*;
import android.util.Log;
public class SmsReciever extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
private static final String TAG = "smsfwd";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "Intent recieved: " + intent.getAction());
if (intent.getAction() == SMS_RECEIVED) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[])bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) { …Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,SMS inbox用一个Activity和一个在Android 中听BroadcastReceiver.
一旦SMS到来,Receiver就会显示Alert消息......
但是我想将消息信息从Receiver发送到Activity.
我不知道如何实现这一目标.
谁知道请帮帮我...
我正在构建一个Android应用程序,BroadcastReceiver我想在onReceive启动时显示一个对话框.我想在手机上显示对话框(无论他在哪里,都会向用户显示一个对话框,比如收到消息时的whatsapp对话框).
我怎么能这样做?
谢谢!
该应用程序拦截短信息并显示一条Dialog消息.
但是我无法Dialog在Test课堂上解决我的错误.我究竟做错了什么?
(我还包括了我的其他2个文件).
Eclipse中显示的错误: AlertDialog.Builder(Test) is undefined
test.java
package com.example.firstapp;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
public class Test extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for …Run Code Online (Sandbox Code Playgroud) 我在Android应用程序中实现了警报.报警工作正常.Toast消息是可见的.
现在我想向用户发出警报框通知.
这是来自ReceiverActivityClass的代码.我试过了
public class ReceiverActivity extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
// Code....
new AlertDialog.Builder(context)
.setTitle("Alert Box")
.setMessage("Msg for User")
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
// some coding...
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
arg0.dismiss();
}
}).create().show();
}
Run Code Online (Sandbox Code Playgroud)
}
android broadcastreceiver android-alarms android-alertdialog