1
내가있어 작업 SMS 수신기에서 의도를 사용하지만 사용하여 다른 클래스를로드 할 때 : 첫 번째에 대한어떻게 수신기 안드로이드
The constructor Intent(SMSReceiver, Class) is undefined
:
Intent intent = new Intent(SMSReceiver.this, SMSNotifier.class);
startActivityForResult(intent, 0);
을 나는이 오류 라인 :
The method startActivityForResult(Intent, int) is undefined for the type SMSReceiver
번째 줄
위한나는 잘못된 점에 관해서 약간의 조언을 정말로 고맙게 생각합니다.
package com.prototype.messages;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
> public class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null) {
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";
}
}
// Context context = getApplicationContext();
String ns = Context.NOTIFICATION_SERVICE;
int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
// Intent notificationIntent = new Intent(SMSReceiver.this, Messages.class);
// notificationIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK);
// PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
notification.setLatestEventInfo(context, contentTitle, contentText, null);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(1, notification);
}
}
대신 어떤 코드를 사용해야합니까? – ng93
@ ng93 : 나는 잘 모른다. 제 코드가 아닌 제 코드입니다. 'SMSReceiver'가'BroadcastReceiver'라고 가정하면, 당신은'Intent'를 만드는데 사용할 수있는'onReceieve()'에'Context'를 전달했습니다. 그러나,'BroadcastReceiver'는'Activity'를 시작해서는 안됩니다. 왜냐하면 그 일이 무엇이든간에 사용자를 방해하기 때문입니다. – CommonsWare
새로운 활동을 시작하기 만하면 상태 표시 줄 알림을 만들 수 있습니다. 나는 SMSReceiver에서 이것을 시도했지만 작동시키지 못했습니다. 아마 내가 SMSReceiver에서 알림을 만드는 방법을 묻는 있어야합니까? – ng93