手机自带功能调用

话不多说自带功能调用,功能不多直接上图:

基本都可以实现,重要的是学习加载方式,百度一下加载URL替换代码加载即可

MainActivity
package com.shaoxin.myapplication;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {
    private LinearLayout activityMain;
    private Button web;
    private Button street;
    private Button phone;
    private Button message;
    private Button send;
    private Button music;
    private Button appmessage;


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

    private void btnListener() {
        MyBtnClickListener mbl = new MyBtnClickListener();
        web.setOnClickListener(mbl);
        street.setOnClickListener(mbl);
        phone.setOnClickListener(mbl);
        message.setOnClickListener(mbl);
        send.setOnClickListener(mbl);
        music.setOnClickListener(mbl);
        appmessage.setOnClickListener(mbl);
    }

    private void init() {
        appmessage = (Button) findViewById(R.id.appmessage);
        activityMain = (LinearLayout) findViewById(R.id.activity_main);
        web = (Button) findViewById(R.id.web);
        street = (Button) findViewById(R.id.street);
        phone = (Button) findViewById(R.id.phone);
        message = (Button) findViewById(R.id.message);
        send = (Button) findViewById(R.id.send);
        music = (Button) findViewById(R.id.music);
    }

    public class MyBtnClickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.message:
                    Uri muri = Uri.parse("smsto://0800000123");
                    Intent mintent = new Intent(Intent.ACTION_VIEW, muri);
                    mintent.putExtra("sms_body", "The SmsText");
                    startActivity(mintent);
                    break;
                case R.id.music:
                    Uri msuri = Uri.parse("file:///sdcard/song.mp3");
                    Intent msintent = new Intent(Intent.ACTION_VIEW, msuri);
                    msintent.setType("audio/mp3");
                    startActivity(msintent);
                    break;
                case R.id.phone:
                    Uri puri = Uri.parse("tel:0800000123");
                    Intent pintent = new Intent(Intent.ACTION_VIEW, puri);
                    startActivity(pintent);
                    break;
                case R.id.send:
                    Uri seuri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
                    Intent seintent = new Intent(Intent.ACTION_VIEW, seuri);
                    startActivity(seintent);
                    break;
                case R.id.street:
                    Uri suri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat startLng&daddr=endLat endLng&hl=en");
                    Intent sintent = new Intent(Intent.ACTION_VIEW, suri);
                    startActivity(sintent);
                    break;
                case R.id.web:
                    Uri wuri = Uri.parse("http://google.com");
                    Intent wintent = new Intent(Intent.ACTION_VIEW, wuri);
                    startActivity(wintent);
                    break;
                case R.id.appmessage:
                    Uri appuri = Uri.fromParts("package", "com.shaoxin.myapplication", null);
                    Intent appintent = new Intent(Intent.ACTION_VIEW, appuri);
                    startActivity(appintent);
                    break;

            }
        }
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.shaoxin.myapplication.MainActivity">

    <Button
        android:id="@+id/web"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="谷歌网站" />
    <Button
        android:id="@+id/street"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="路径规划" />
    <Button
        android:id="@+id/phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="打电话" />
    <Button
        android:id="@+id/message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="调用短信程序" />
    <Button
        android:id="@+id/send"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="多媒体二" />
    <Button
        android:id="@+id/music"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="播放多媒体" />
    <Button
        android:id="@+id/appmessage"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="卸载APP"/>
</LinearLayout>

代码拷过去可以直接运行

 

posted @ 2016-12-13 20:33  情似雨餘黏地絮  阅读(249)  评论(0编辑  收藏  举报