Unit - 07 Using SMS

Lesson Plan: Unit - 07
Subject: P15A2AAD - Android Application Development
Topic of Study: Using SMS
Grade/Level: Master of Computer Applications
Objective: Using SMS
Time Allotment: 55 Minutes


  • Using SMS
    • SMS functionality is provided to applications through the android.telephony package.
    • Permission to Send and Receive SMS Messages
      • android.permission.SEND_SMS
      • android.permission.RECEIVE_SMS
    • To send an SMS, an application first needs to get an instance of the SmsManager by calling the static method getDefault().
      • sms.sendTextMessage("5554", null, "Hello from 5554", null, null);
    • SmsManager API
      • SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("phoneNo", null, "sms message", null, null); 
    • Built-in SMS application
      • Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.putExtra("sms_body", "default content"); sendIntent.setType("vnd.android-dir/mms-sms"); startActivity(sendIntent); 
    • Permission:
      • There were times when your app needed to get permission to do something, including when it needed to:
        • connect to the Internet.
        • use a content provider in another app. 
      • An app is free to use any resources or data that it creates, but must get permission to use anything—data, resources, hardware, software—that does not belong to it. 
      • For example, your app must get permission to read the user's Contacts data, or to use the device's camera. 
      • To request permission, add the attribute to the Android manifest file, along with the name of the requested permission. 
      • For example, to get permission to use the camera:  
      • The Android framework provides more than 100 predefined permissions .
    • Types of Permission:
      • Android classifies permissions as normal or dangerous.
      • Android automatically grants normal permissions but asks the user to explicitly grant dangerous permissions. 
      • A normal permission is for actions that do not affect user privacy or user data, such as connecting to the Internet.
      • A dangerous permission is for an action that does affect user privacy or user data, such as permission to write to the user's voicemail. 
    • How users grant and revoke permissions:
      • The way users grant and revoke permissions depends on:
      • The version of Android that the device is running.
      • The version of Android that the app was created for. 
      • Before Marshmallow (Android 6.0) 
        • If an app was created for a version of Android before 6.0 (Marshmallow) or it is running on a device that uses a version of Android before Marshmallow, Google Play asks the user to grant required dangerous permissions before installing the app. 
      • After Marshmallow (Android 6.0) 
        • If an app was created for a version of Android from Android 6.0 (Marshmallow) onwards and it is running on a device that uses a version of Android from Marshmallow onwards, then Google Play does not ask the user to grant dangerous permissions to the app before installing it. Instead, when the user starts to do something in the app that needs that level of permission, Android shows a dialog box asking the user to grant permission. 
    • How differences in the permissions models affect developers:
      • In the "old" permissions model, Google Play and the Android Framework worked together to get permission from the user.
      • All that the developer needed to do was to make sure that the app listed the permissions it needed in the Android manifest file. 
      • The developer could assume that if the app was running, then the user had granted permission. 
      • The developer did not need to write code to check if permission had been granted or not.
      • In the "new" permissions model, you can no longer assume that if the app is running, then the user has granted the needed permissions. 
      • The user could grant permission the first time they run the app, then, at any time, change their mind and revoke any or all of the permissions that the app needs. 
      • So, the app must check whether it still has permission every time it does something that requires permission.
    • How it Works
  • Run Time Permission using code.
  • Send SMS code.
  • Received SMS
    • Applications can also receive SMS messages.
    • To do so, your application must register a Broadcast Receiver to listen for the Interaction associated with receiving an SMS. 
    • An application listening to SMS in this way doesn’t prevent the message from getting to other applications.
    • Step 01: Create Class
    • Step 02: Register with manifest & add permission




       
           
               

               
           

       
   
   

1 Comments

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form