В этом уроке мы создадим приложение, которое будет вызывать системные приложения: интернет-браузер — чтобы открыть ссылку, диалер — чтобы позвонить по номеру, и приложение Google-карты — чтобы показать на карте заранее определенные координаты.
Скачать файлы для установки Google Apps на эмулятор Genymotion
Код проекта — под видео:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<Button
android:id="@+id/btnWeb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="Web">
</Button>
<Button
android:id="@+id/btnMap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="Map">
</Button>
<Button
android:id="@+id/btnCall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:text="Call">
</Button>
</LinearLayout>
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button btnWeb;
Button btnMap;
Button btnCall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnWeb = (Button) findViewById(R.id.btnWeb);
btnMap = (Button) findViewById(R.id.btnMap);
btnCall = (Button) findViewById(R.id.btnCall);
btnWeb.setOnClickListener(this);
btnMap.setOnClickListener(this);
btnCall.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent;
switch (v.getId()) {
case R.id.btnWeb:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://developer.android.com"));
startActivity(intent);
break;
case R.id.btnMap:
intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:-0.45609946,-90.26607513"));
startActivity(intent);
break;
case R.id.btnCall:
intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:12345"));
startActivity(intent);
break;
}
}
}
Больше уроков:
Инструменты android разработчика: тут
Дизайн android приложений: тут
Уроки создания игр для android: тут
Основы программирования на JAVA: тут
<<Урок 30. Используем requestCode и resultCode в onActivityResult | Уроки Android Studio
Урок 32. Создаем простое приложение – интернет браузер для андроид>>
Здравствуйте Виталий! Большое спасибо за Ваши уроки, которые очень грамотно преподносятся, что даже такой далекий от программирования человек, как я, смог разобраться. У меня к Вам вопрос: при вызове intent c действием ACTION_CALL происходит звонок по заданному в Uri номеру, можно ли программно узнать когда абонент поднимет трубку? Заранее благодарен за помощь.