2013-04-22 66 views
0

此代碼不能與Android版本4.1.2工作,我可以在android 4.1.2中發送「SMS received intent」嗎?

private static void createFakeSms(Context context, String sender,String body) 
{ 
    byte[] pdu = null; 
    byte[] scBytes = PhoneNumberUtils.networkPortionToCalledPartyBCD("0000000000"); 
    byte[] senderBytes = PhoneNumberUtils.networkPortionToCalledPartyBCD(sender); 
    int lsmcs = scBytes.length; 
    byte[] dateBytes = new byte[7]; 
    Calendar calendar = new GregorianCalendar(); 
    dateBytes[0] = reverseByte((byte) (calendar.get(Calendar.YEAR))); 
    dateBytes[1] = reverseByte((byte) (calendar.get(Calendar.MONTH) + 1)); 
    dateBytes[2] = reverseByte((byte) (calendar.get(Calendar.DAY_OF_MONTH))); 
    dateBytes[3] = reverseByte((byte) (calendar.get(Calendar.HOUR_OF_DAY))); 
    dateBytes[4] = reverseByte((byte) (calendar.get(Calendar.MINUTE))); 
    dateBytes[5] = reverseByte((byte) (calendar.get(Calendar.SECOND))); 
    dateBytes[6] = reverseByte((byte) ((calendar.get(Calendar.ZONE_OFFSET) + calendar 
.get(Calendar.DST_OFFSET))/(60 * 1000 * 15))); 
    try 
    { 
    ByteArrayOutputStream bo = new ByteArrayOutputStream(); 
    bo.write(lsmcs); 
    bo.write(scBytes); 
    bo.write(0x04); 
    bo.write((byte) sender.length()); 
    bo.write(senderBytes); 
    bo.write(0x00); 
    bo.write(0x00); // encoding: 0 for default 7bit 
    bo.write(dateBytes); 
    try 
    { 
     String sReflectedClassName = "com.android.internal.telephony.GsmAlphabet"; 
     Class cReflectedNFCExtras = Class.forName(sReflectedClassName); 
     Method stringToGsm7BitPacked = cReflectedNFCExtras.getMethod(
     "stringToGsm7BitPacked", new Class[] { String.class }); 
     stringToGsm7BitPacked.setAccessible(true); 
     byte[] bodybytes = (byte[]) stringToGsm7BitPacked.invoke(null,body); 
     bo.write(bodybytes); 
    } 
    catch (Exception e) 
    { 
    } 
    pdu = bo.toByteArray(); 
    } 
    catch (IOException e) 
    { 
    } 
    Intent intent = new Intent(); 
    intent.setClassName("com.android.mms", 
      "com.android.mms.transaction.SmsReceiverService"); 
    intent.setAction("android.provider.Telephony.SMS_RECEIVED"); 
    intent.putExtra("pdus", new Object[] { pdu }); 
    intent.putExtra("format", "3gpp"); 
    context.startService(intent); 
} 

private static byte reverseByte(byte b) { 
    return (byte) ((b & 0xF0) >> 4 | (b & 0x0F) << 4); 
} 

當我打電話context.startService(intent)我得到這個例外

java.lang.SecurityException: Not allowed to start service Intent { act=android.provider.Telephony.SMS_RECEIVED cmp=com.android.mms/.transaction.SmsReceiverService (has extras) } without permission not exported from uid 10046** 

虛擬設備4.1.2它完美但不是在我的GS2設備。

任何人都可以幫助我嗎?

回答

4

在Android的新版本中,這是一個受保護的廣播,出於安全原因只能由系統應用程序發送。

只有這樣,才能讓您的應用程序發送是說服OEM,以使他們的ROM

+1

THANKS上的系統應用程序!現在我打電話給Android OEM,並試圖說服他們。 :-) – 2013-04-23 08:27:13

相關問題