SMS를 통해 화면을 켜고 끕니다. 여기에 내 코드는 내가 잘못 찾았는지 모르겠다. 전혀 작동하지 않아서 오류를 찾는데 도움이된다. 매니페스트 파일도 첨부하고 있습니다. 미리 감사드립니다. 내 자바 파일 :SMS를 통해 화면을 켜고 끕니다.
public class MyReceiver extends BroadcastReceiver{
String sender;
@Override
public void onReceive(Context context, Intent intent) {
SmsMessage[] sms = null;
Bundle b = intent.getExtras();
String str = " SMS From : ";
if (b != null) {
Object[] pdus = (Object[]) b.get("pdus");
sms = new SmsMessage[pdus.length];
for (int i = 0; i < sms.length; i++) {
sms[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
if (i == 0) {
str += sms[i].getOriginatingAddress();
str += ":"+sms[i].getMessageBody().toString();
}else if (sms[i].getMessageBody().equals("D")) {
Intent in2= new Intent(Intent.ACTION_SCREEN_OFF);
in2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in2);
}else if (sms[i].getMessageBody().equals("E")) {
Intent in3= new Intent(Intent.ACTION_SCREEN_ON);
in3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in3);
}
}
}
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
Log.d("Receiving", str);
}
}
}
MY 매니페스트 파일 :
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<receiver android:name=".MyReceiver">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<action android:name="android.intent.action.SCREEN_OFF"/>
<action android:name="android.intent.action.SCREEN_ON"/>
</intent-filter>
</receiver>
</application>
SMS를 수신하지 않거나 화면을 켜거나 끄지 않습니다? – cYrixmorten
수신시 화면을 켜고 끄지 않지만 몇 번 시도한 후에 SMS 수신을 멈추더라도 SMS 수신에 축배를 보여 주어야합니다. – Disguise
수신기 내부에서 너무 많은 작업을하고 있습니다. 당신이해야 할 일은 의도를 받아들이고 작업을 수행 할 활동이나 서비스에 제어권을 넘기는 것입니다. –