Intent Dr Sandip Mal Explicit Intent Create project

  • Slides: 11
Download presentation
Intent Dr. Sandip Mal

Intent Dr. Sandip Mal

Explicit Intent • • Create project Open activity_main XML file and put some view

Explicit Intent • • Create project Open activity_main XML file and put some view and submit button Create new activity in layout and name it activity 2. xml. Add views in the activity. Goto Main. Activity. java file and add the following code. public void openactivity(View view) { Intent intent=new Intent(this, Main 2 Activity. class); start. Activity(intent); } • Run Application

Implicit Intent

Implicit Intent

Calling Application <? xml version="1. 0" encoding="utf-8"? > <Relative. Layout xmlns: android="http: //schemas. android.

Calling Application <? xml version="1. 0" encoding="utf-8"? > <Relative. Layout xmlns: android="http: //schemas. android. com/apk/res/android" xmlns: app="http: //schemas. android. com/apk/res-auto" xmlns: tools="http: //schemas. android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent" tools: context=". Main. Activity"> <Edit. Text android: id="@+id/edit. Text" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_align. Parent. Top="true" android: layout_center. Horizontal="true" android: layout_margin. Top="130 dp" android: ems="10" android: input. Type="phone" /> <Image. View android: id="@+id/image. View" android: layout_width="69 dp" android: layout_height="66 dp" android: layout_center. In. Parent="true" app: src. Compat="@drawable/ic_call_black_24 dp" /> </Relative. Layout>

 • Declare private static final int request_call=1; private Edit. Text et; • Define

• Declare private static final int request_call=1; private Edit. Text et; • Define in on. Create Function et=find. View. By. Id(R. id. edit. Text); Image. View img=find. View. By. Id(R. id. image. View); img. set. On. Click. Listener(new View. On. Click. Listener() { @Override public void on. Click(View view) { make. Phone. Call(); } });

 • Create Phone Call Function private void make. Phone. Call(){ String number =et.

• Create Phone Call Function private void make. Phone. Call(){ String number =et. get. Text(). to. String(); if(number. trim(). length()>0) { if (Context. Compat. check. Self. Permission(Main. Activity. this, Manifest. permission. CALL_PHONE)!= Package. Manager. PERMISSION_GRANTED){ Activity. Compat. request. Permissions(Main. Activity. this, new String[]{Manifest. permission. CALL_PHONE}, request_call); } else{ String dial="tel: "+number; start. Activity(new Intent(Intent. ACTION_CALL, Uri. parse(dial))); } } else{ Toast. make. Text(Main. Activity. this, "Enter phone Number", Toast. LENGTH_LONG). show(); } }

On Request Permission public void on. Request. Permissions. Result(int request. Code, @Non. Null String[]

On Request Permission public void on. Request. Permissions. Result(int request. Code, @Non. Null String[] permissions, @Non. Null int[] grant. Results) { super. on. Request. Permissions. Result(request. Code, permissions, grant. Results); if(request. Code==request_call){ if(grant. Results. length>0 && grant. Results[0]==Package. Manager. PERMISSION_GRANTED){ make. Phone. Call(); } else{ Toast. make. Text(this, "Permission Denied", Toast. LENGTH_LONG). show(); } } }

Messaging Application activity_main. xml <? xml version="1. 0" encoding="utf-8"? > <Relative. Layout xmlns: android="http:

Messaging Application activity_main. xml <? xml version="1. 0" encoding="utf-8"? > <Relative. Layout xmlns: android="http: //schemas. android. com/apk/ res/android" xmlns: app="http: //schemas. android. com/apk/re s-auto" xmlns: tools="http: //schemas. android. com/tools" android: layout_width="match_parent" android: layout_height="match_parent" app: layout_behavior="@string/appbar_scrollin g_view_behavior" tools: context=". Main. Activity" tools: show. In="@layout/activity_main"> <Edit. Text android: id="@+id/edit. Text" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_align. Parent. Top="true" android: layout_center. Horizontal="true" android: layout_margin. Top="43 dp" android: ems="10" android: hint="Enter number" android: input. Type="phone" /> <Edit. Text android: id="@+id/edit. Text 1" android: layout_width="249 dp" android: layout_height="176 dp" android: layout_align. Parent. Top="true" android: layout_center. Horizontal="true" android: layout_margin. Top="133 dp" android: ems="10" android: hint="message" android: input. Type="text. Multi. Line" /> <Button android: id="@+id/button" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_align. Parent. Bottom="true" android: layout_center. Horizontal="true" android: layout_margin. Bottom="84 dp" android: text="Button" /> </Relative. Layout>

Android_manifest. xml <uses-permission android: name="android. permission. SEND_SMS"></usespermission> <uses-permission android: name="android. permission. RECEIVE_SMS"></usespermission>

Android_manifest. xml <uses-permission android: name="android. permission. SEND_SMS"></usespermission> <uses-permission android: name="android. permission. RECEIVE_SMS"></usespermission>

Declare Variables Edit. Text mobileno, message; Button sendsms; • Define following within oncreate mobileno=(Edit.

Declare Variables Edit. Text mobileno, message; Button sendsms; • Define following within oncreate mobileno=(Edit. Text)find. View. By. Id(R. id. edit. Text 1); message=(Edit. Text)find. View. By. Id(R. id. edit. Text 2); sendsms=(Button)find. View. By. Id(R. id. button 1); • – Define the following function sendsms. set. On. Click. Listener(new On. Click. Listener() { public void on. Click(View arg 0) { String no=mobileno. get. Text(). to. String(); String msg=message. get. Text(). to. String(); //Getting intent and Pending. Intent instance Intent intent=new Intent(get. Application. Context(), Main. Activity. class); Pending. Intent pi=Pending. Intent. get. Activity(get. Application. Context(), 0, intent, 0); //Get the Sms. Manager instance and call the send. Text. Message method to send message Sms. Manager sms=Sms. Manager. get. Default(); sms. send. Text. Message(no, null, msg, pi, null); Toast. make. Text(get. Application. Context(), "Message Sent successfully!", Toast. LENGTH_LONG). show(); } });