+ All Categories
Home > Documents > message-delay

message-delay

Date post: 14-Apr-2017
Category:
Upload: eman-magdy
View: 212 times
Download: 2 times
Share this document with a friend
20
Transcript

what is Message delayer ?!

Its an android application that make user to send message after a small delay that can

make the user easy to send a message during his meeting or

while driving…etc.

Open eclipse

To start first android

project click start a new

android studio project

Here we need to choose the min API we want to work on then next

Choose a blank activity to work on and click next then you can find these window to rename your activity

Click here to write the code

Insert component

APP GUI Your java project

Click here to show GUI code

Click here to show Xml file

GUI Code file

Write your code here

You write your code in onCreat method

Text Field

Text Field Insert Text edit GUI

Text

Button

Prepare your layout

Text field you can choose up to what you want to write on it

Widgets to make a text to

put like an outline

Change the id of every element you use

In the layout we can put name to every view we use like (text ,text field,button,…etc.) and although we can give it an ID to make it easy to get to it when want to use it

Our code

final Button sender = (Button) findViewById(R.id.button1); final EditText no= (EditText) findViewById(R.id.tn); final EditText msg = (EditText) findViewById(R.id.tm); final EditText delay = (EditText) findViewById(R.id.ed); sender.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Runnable clickButton = new Runnable() { @Override public void run() { SmsManager manager=SmsManager.getDefault(); String message=msg.getText().toString(); String number=no.getText().toString(); manager.sendTextMessage(number, null, message, null, null); Toast.makeText(getApplicationContext(), "send succesfully", Toast.LENGTH_LONG).show(); } }; int v1= Integer.parseInt(delay.getText().toString()) ; sender.postDelayed(clickButton, v1*1000); //Delay for v seconds to show the result }});

To get ids of layout As variable to use it in code

This a function that happen When click on Button

Code of access message

Toast is function to show Message to user

Number to send it message Note : it is string

Your message string

Delay variable

Delay in seconds

This file to add permissions to access Android services

Open it to add message access permission In our case

Important

Put only the permission of user to make send_sms

To get APK file to install it on mobile

Open project file

Send it to mobile and install it

By Eman magdy

Thanks

By eman magdy


Recommended