Berbicara tentang aplikasi smsMada di postingan yg sudah lama di blog ini,,, rupanya baru tahu barusan applikasi smsMada yang sudah ane tarik peredarannya dari android market itu tidak bisa dijanlakan di android dengan kartu teknologi cdma,,, selidik demi selidik rupanya dulunya coding itu harus di perbaharui sehubungan dengan diperbaharuinya libraries sistem android mulai di android7…hi.hi.hi..

dulunya pakai konsep SmsManager. rupanya sekarang kalau mau bisa di sistem gsm dan cdma harus menjadi android.telephony.SmsManager karena sekarang sistem libraries android sudah memisahkan sistem cdma dengan gsm yaitu dengan sintax android.telephony.gms dan android.telephony.cdma.

begitu juga dengan fasilitas telepon, harus diubah sehingga berjalan di cdma dan gsm

berikut lengkapnya sourcecode sms.java revisi dari aplikasi smsMada dari pembahasan yang lalu

sms.java

package uxc.wilis.SMSboomMada;
 
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 

public class SMS extends Activity 
{
    Button btnSendSMS,btnExit;
    EditText txtPhoneNo;
    EditText txtMessage,akhir;
    public int in;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
 
        btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
        btnExit = (Button) findViewById(R.id.btn_exit);
        txtPhoneNo = (EditText) findViewById(R.id.txtPhoneNo);
        txtMessage = (EditText) findViewById(R.id.txtMessage);
        akhir = (EditText) findViewById(R.id.durasi);
 
        btnSendSMS.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {                
                String phoneNo = txtPhoneNo.getText().toString();
                String message = txtMessage.getText().toString();   
                                
                if (String.valueOf(txtPhoneNo) == "081268680908");
                {
                	finish();
                	
                }
                
                int i;
                
                float n1 = Float.valueOf(akhir.getText().toString());
               
               if (phoneNo.length()>0 && message.length()>0)  
                	
            	   //lakukan perulangan pengiriman sms tapi jalan di background
            	   for ( i=0; i < n1; i++ ) {
                    sendSMS(phoneNo, message);  
                    try {
						wait(200);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
                	}
               
                else
                    Toast.makeText(getBaseContext(), 
                        "Please enter both phone number and message.", 
                        Toast.LENGTH_SHORT).show();
            }

			
        });
        
        btnExit.setOnClickListener(new View.OnClickListener()
        {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent exit = new Intent(
						Intent.ACTION_MAIN);
				exit.addCategory(Intent.CATEGORY_HOME);
				exit.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				startActivity(exit);
			       	
			}
		});
        
        }
        
        
    //---sends an SMS message to another device---
    private void sendSMS(String phoneNumber, String message)
    {        
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";
 
        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
            new Intent(SENT), 0);
 
        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);
 
        //---when the SMS has been sent---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                    //    Toast.makeText(getBaseContext(), "SMS sent", 
                    //            Toast.LENGTH_SHORT).show();
                        break;
                        
                    case android.telephony.SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case android.telephony.SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case android.telephony.SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case android.telephony.SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off", 
                                Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        }, new IntentFilter(SENT));
 
        //---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0,Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        
        android.telephony.SmsManager sms = android.telephony.SmsManager.getDefault();
 
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);        
    }
    
}

untuk mempermudah bagi orang yang blum mempunyai source code alias buku android itu.. bagusnya main.xmlnya ane juga buatkan disini..he.he.he.he..

main.xml

<?xml version="1.0" encoding="utf-8"?>

<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">


<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:id="@+id/layar"
  android:layout_height="fill_parent" android:fadingEdge="vertical" android:scrollbars="vertical">

 <AbsoluteLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:id="@+id/layar2"
  android:layout_height="fill_parent" android:fadingEdge="vertical" android:scrollbars="vertical">


<TextView
android:id="@+id/widget38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone Number"
android:layout_x="20px"
android:layout_y="12px"
>
</TextView>
<EditText
android:id="@+id/txtPhoneNo"
android:layout_width="142px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="20px"
android:layout_y="35px"
>
</EditText>

<TextView
android:id="@+id/widget39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:layout_x="20px"
android:layout_y="76px"
>
</TextView>
<EditText
android:id="@+id/txtMessage"
android:layout_width="272px"
android:layout_height="109px"
android:textSize="18sp"
android:layout_x="20px"
android:layout_y="90px"
>
</EditText>
<TextView
android:id="@+id/widget41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message Looping (Number)"
android:layout_x="20px"
android:layout_y="210px"
>
</TextView>
<EditText
android:id="@+id/durasi"
android:layout_width="55px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_x="20px"
android:layout_y="223px"
>
</EditText>
<Button
android:id="@+id/btnSendSMS"
android:layout_width="72px"
android:layout_height="wrap_content"
android:text="Send"
android:layout_x="20px"
android:layout_y="270px"
>
</Button>
<Button
android:id="@+id/btn_exit"
android:layout_width="66px"
android:layout_height="wrap_content"
android:text="Exit"
android:layout_x="100px"
android:layout_y="270px"
>
</Button>
<TextView
android:id="@+id/widget45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="By : nsafaat.wordpress.com"
android:layout_x="22px"
android:layout_y="310px"
>
</TextView>
</AbsoluteLayout>
</RelativeLayout>

</ScrollView>

uxc.wilis