I am new in Android. I want to send a sms in pdu mode and i found this code, but some class doesn't Support in android studio (Bold Lines). Can anyone help me ?
private void sendsmsBypdu(String phoneNumber,String message) {
int size;
Field f;
Log.d(TAG,"Retrieving phone instance ...");
ContactsContract.CommonDataKinds.Phone phone = **PhoneFactory.getDefaultPhone();**
/* Get IccSmsInterfaceManager */
Log.d(TAG,"Retrieving SmsInterfaceManager ...");
**IccSmsInterfaceManager ismsm = getIccSmsInterfaceManager();**
try {
Log.d(TAG,"Retrieving mDispatcher ...");
**f = IccSmsInterfaceManager.class.getDeclaredField("mDispatcher");**
f.setAccessible(true);
SmsManager sms_smg = (SmsManager)f.get(ismsm);
Log.d(TAG, "Formatting class 0 SMS ...");
byte[] b = new byte[0];
SmsMessage.SubmitPdu pdus = SmsMessage.getSubmitPdu(null, phoneNumber, message,false);
/* change class to Class 0 */
size = (int)pdus.encodedMessage[2];
size = (size/2) + (size%2);
pdus.encodedMessage[size+5] = (byte)0xF0;
/* send raw pdu */
Log.d(TAG,"Sending SMS via sendRawPdu() ...");
try
{
/* Android 2.2 -> 4.0.* */
Method m = SmsManager.class.getDeclaredMethod("sendRawPdu", b.getClass(), b.getClass(), PendingIntent.class, PendingIntent.class);
m.setAccessible(true);
m.invoke(sms_smg, pdus.encodedScAddress, pdus.encodedMessage, null, null);
}
catch(NoSuchMethodException e)
{
/* Android 4.1.2 */
Method m = SmsManager.class.getDeclaredMethod("sendRawPdu", b.getClass(), b.getClass(), PendingIntent.class, PendingIntent.class, String.class);
m.setAccessible(true);
m.invoke(sms_smg, pdus.encodedScAddress, pdus.encodedMessage, null, null, phoneNumber);
}
Log.d(TAG, "SMS sent");
} catch (SecurityException e) {
Log.e(TAG, "Exception: Security !");
e.printStackTrace();
}
catch (NoSuchFieldException e) {
Log.e(TAG, "Exception: Field mDispatcher not found !");
e.printStackTrace();
} catch (IllegalArgumentException e) {
Log.e(TAG, "Exception: Illegal Argument !");
e.printStackTrace();
} catch (IllegalAccessException e) {
Log.e(TAG, "Exception: Illegal access !");
e.printStackTrace();
} catch (NoSuchMethodException e) {
Log.e(TAG, "Exception: sendRawPdu() not found !");
e.printStackTrace();
} catch (InvocationTargetException e) {
Log.e(TAG, "Exception: cannot invoke sendRawPdu() !");
e.printStackTrace();
}
}
I found my Answer. More About this you can read in Hush SMS