ここは新しいです。私はSMSメッセージに警告を表示する必要があるアプリを作っている。 私はどのように私が理解しているとは思わない。関数が "this"属性を持っている場合、別のクラスから関数を呼び出すことができます。smsRecevicerクラスのアラートに関する問題
しかし、この行は動作しません:
AlertDialog.Builder(this).setTitle("asd").setMessa ge(str).setNegativeButton("Annuller", null).setPositiveButton("Bekræft", null).show();
を、私はそれがあるため、このクラスの実行Iの背景または何であるかどうかわからないのですか?
これはクラスです:
package net.sms;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.widget.Toast;
public class SmsReceiver 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 (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
AlertDialog.Builder alt_bld = new AlertDialog.Builder(context);
alt_bld.setTitle("aaa");
alt_bld.show();
//new AlertDialog.Builder(this).setTitle("asd").setMessage(str).setNegativeButton("Annuller", null).setPositiveButton("Bekræft", null).show();
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
}