package com.example.myapplication08101;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

TextView textview;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button btn1 = (Button) findViewById(R.id.button);

//监听button事件
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openBaiduNavi();
}
});

}
/**
* 启动高德App进行导航
* sourceApplication 必填 第三方调用应用名称。如 amap
* poiname 非必填 POI 名称
* dev 必填 是否偏移(0:lat 和 lon 是已经加密后的,不需要国测加密; 1:需要国测加密)
* style 必填 导航方式(0 速度快; 1 费用少; 2 路程短; 3 不走高速;4 躲避拥堵;5 不走高速且避免收费;6 不走高速且躲避拥堵;7 躲避收费和拥堵;8 不走高速躲避收费和拥堵))
*/
private void openGaoDeNavi() {
StringBuffer stringBuffer = new StringBuffer("androidamap://navi?sourceApplication=")
.append("yitu8_driver").append("&lat=").append("34.264642646862")
.append("&lon=").append("108.95108518068")
.append("&dev=").append(1)
.append("&style=").append(0);
;
// if (!TextUtils.isEmpty(poiname)) {
// stringBuffer.append("&poiname=").append(poiname);
// }
Intent intent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(stringBuffer.toString()));
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setPackage("com.autonavi.minimap");
startActivity(intent);
}

/**
* 打开百度地图导航客户端
* intent = Intent.getIntent("baidumap://map/navi?location=34.264642646862,108.95108518068&type=BLK&src=thirdapp.navi.you
* location 坐标点 location与query二者必须有一个,当有location时,忽略query
* query 搜索key 同上
* type 路线规划类型 BLK:躲避拥堵(自驾);TIME:最短时间(自驾);DIS:最短路程(自驾);FEE:少走高速(自驾);默认DIS
*/
private void openBaiduNavi() {
StringBuffer stringBuffer = new StringBuffer("baidumap://map/navi?location=")
.append("28.680242").append(",").append("115.980541").append("&type=TIME");
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(stringBuffer.toString()));
intent.setPackage("com.baidu.BaiduMap");
startActivity(intent);
}

public String GetPhoneNum() {
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);


@SuppressLint("MissingPermission") String tel = tm.getLine1Number();//手机号码


return tel;
}
}