Android 实现电话拨打,照相,地图显示,信息发送
**
Android实现打电话,照相,地图显示
**
注:本人只是一个关于编程的菜鸟,希望大家在看了我的文章后多多指点呦。
- 在AndroidMainfest.xml中添加权限
- 在layout.xml中添加如下代码
*注意:这里只是部分的截图,不要照着盲目敲,年轻人还是要多多学习!
- OK,不要开心,这里你只完成了不到一半,下面来跟着我继续进行
package com.example.ditu;
import android.Manifest;
import android.content.ClipData;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import java.util.List;
public class MainActivity extends AppCompatActivity {
ImageButton imageButton;
ImageButton imageButton1;
ImageView imageView;
ImageButton imageButton2;
private static int REQUEST_CAMERA=3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageButton1=findViewById(R.id.phone1);
imageButton2=findViewById(R.id.c);
imageButton=findViewById(R.id.phone);
imageView=findViewById(R.id.b);
imageButton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri=Uri.parse("http://www.google.cn/maps/@29.491271,160.570215,17z");
Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
}
});
imageButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view.getId()==R.id.phone1){
Intent intent1=new Intent();
intent1.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent1,REQUEST_CAMERA);
}
}
});
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent();
intent.setClass(MainActivity.this,PhoneActivity.class);
startActivity(intent);
}
});
}
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
if (data==null) return;
Bundle bundle=data.getExtras();
Bitmap b=(Bitmap) bundle.get("data");
imageView.setImageBitmap(b);
}
}
在Java文件夹中创建一个名为People的Java Class
package com.example.ditu;
import java.io.Serializable;
public class People implements Serializable{
private String name;
private String number;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setNumber(String number) {
this.number = number;
}
public String getNumber() {
return number;
}
}
在MainActivity中输入如下代码
package com.example.ditu;
import android.Manifest;
import android.content.ClipData;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import java.util.List;
public class MainActivity extends AppCompatActivity {
ImageButton imageButton;
ImageButton imageButton1;
ImageView imageView;
ImageButton imageButton2;
private static int REQUEST_CAMERA=3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageButton1=findViewById(R.id.phone1);
imageButton2=findViewById(R.id.c);
imageButton=findViewById(R.id.phone);
imageView=findViewById(R.id.b);
imageButton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri uri=Uri.parse("http://www.google.cn/maps/@29.491271,160.570215,17z");
Intent intent=new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
}
});
imageButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view.getId()==R.id.phone1){
Intent intent1=new Intent();
intent1.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent1,REQUEST_CAMERA);
}
}
});
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent();
intent.setClass(MainActivity.this,PhoneActivity.class);
startActivity(intent);
}
});
}
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
if (data==null) return;
Bundle bundle=data.getExtras();
Bitmap b=(Bitmap) bundle.get("data");
imageView.setImageBitmap(b);
}
}
运行效果展示