android中顯示意圖和隱式意圖(附帶實現(xiàn)打電話)-創(chuàng)新互聯(lián)

未來的我,希望能看到這篇文章的時候,想一想什么都走過來了,還有什么走不得呢,無論何時何地,不要停下學習的腳步。

創(chuàng)新互聯(lián)建站堅持“要么做到,要么別承諾”的工作理念,服務領域包括:網(wǎng)站制作、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的撫遠網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!

android 中顯示意圖和隱式意圖(附帶實現(xiàn)打電話)

android 中顯示意圖和隱式意圖(附帶實現(xiàn)打電話)

mainactivity篇

package com.example.qingdan;

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.net.Uri;

import android.view.Menu;

import android.view.View;

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

public void click1(View v) {

//【1】創(chuàng)建意圖對象

Intent intent =new Intent();

//【2】設置撥打電話的動作

intent.setAction(Intent.ACTION_CALL);

//【3】設置撥打的數(shù)據(jù)

intent.setData(Uri.parse("tel:"+119));

//【4】開啟Activity

startActivity(intent);

}

//隱式意圖

public void click2(View v){

//[1]創(chuàng)建意圖對象

Intent intent=new Intent();

//[2]設置跳轉(zhuǎn)的動作

intent.setAction("com.iteheima.comm");

//設置category

intent.addCategory("android.intent.category.DEFAULT");

//設置數(shù)據(jù)

//intent.setData(Uri.parse("itheima:"+110));

//設置數(shù)據(jù)類型

//intent.setType("aa/bb");//調(diào)用setdate會自動清除setdata

//所以出現(xiàn)此種情況,我們應該調(diào)用如下編程

intent.setDataAndType(Uri.parse("itheima:"+110), "aa/bb");//itheima是data中已經(jīng)配置好了的,所以上述同理只能用‘tel’

//開啟activity

startActivity(intent);

}

//顯示意圖

//點擊按鈕跳轉(zhuǎn)到 TestActivity

public void click3(View v) {

//[1]創(chuàng)建意圖對象  意圖就是我要完成一件事

Intent intent = new Intent(this,test3activity.class);

//[2]設置包名和類名 packageName:當前應用的包名

//intent.setClassName("com.itheima.newactivity", "com.itheima.newactivity.Test3Activity");

//[3]開啟Activity

startActivity(intent);

}

}

test3activity篇

package com.example.qingdan;

import android.os.Bundle;

import android.app.Activity;

public class test3activity extends Activity{

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO 自動生成的方法存根

super.onCreate(savedInstanceState);

//加載布局

setContentView(R.layout.activity_test);

}

}

testactivity篇

package com.example.qingdan;

import android.app.Activity;

import android.os.Bundle;

public class testactivity extends Activity{

//當Activity

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO 自動生成的方法存根

super.onCreate(savedInstanceState);

//加載布局

setContentView(R.layout.activity_test);

}

}

layout——activitymain篇

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

  xmlns:tools="http://schemas.android.com/tools"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="vertical"

  tools:context=".MainActivity" >

  <Button

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:onClick="click1"

  android:text="撥打電話"/>

  <Button

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:onClick="click2"

  android:text="跳轉(zhuǎn)到activity"/>

  <Button

  android:layout_width="wrap_content"

  android:layout_height="wrap_content"

  android:onClick="click3"

  android:text="跳轉(zhuǎn)到activity"/>

</LinearLayout>

activitymain——test3篇

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="vertical" >

  <TextView

    android:layout_width="match_parent"

  android:layout_height="wrap_content"

  android:text="wo shi test"

    />

</LinearLayout>

activitymain-test篇

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

  android:layout_width="match_parent"

  android:layout_height="match_parent"

  android:orientation="vertical" >

  <TextView

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:text="我是testActivity333" />

</LinearLayout>

android manifest篇

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

  package="com.example.qingdan"

  android:versionCode="1"

  android:versionName="1.0" >

  <uses-sdk

    android:minSdkVersion="8"

    android:targetSdkVersion="17" />

  <uses-permission android:name="android.permission.CALL_PHONE"/>

  <application

    android:allowBackup="true"

    android:icon="@drawable/ic_launcher"

    android:label="@string/app_name"

    android:theme="@style/AppTheme" >

    <activity

      android:name="com.example.qingdan.MainActivity"

       android:icon="@drawable/head1"

      android:label="我是第二個頁面" >

      <intent-filter>

        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />

      </intent-filter>

    </activity>

    <activity

      android:name="com.example.qingdan.testactivity"

       android:icon="@drawable/head2"

      android:label="我是第一個頁面" >

                《!----》主入口》

      <intent-filter>

        <action android:name="com.iteheima.comm" />

        <data android:scheme="itheima"

          android:mimeType="aa/bb"

          />

        <category android:name="android.intent.category.DEFAULT" />

      </intent-filter>

      《!我們可以創(chuàng)建出多個過濾器,只要,前面name,category能匹配到就行了,有一個就行哪怕data改變也可以》

      <intent-filter>

        <action android:name="com.iteheima.comm" />

        <data android:scheme="itheima"

          android:mimeType="aa/bb"

          />

        <category android:name="android.intent.category.DEFAULT" />

      </intent-filter>

    </activity>

     <!--配置Activity3 -->

    <activity android:name="com.example.qingdan.test3activity"></activity>

  </application>

</manifest>

ok,結(jié)束,主要是自己太累了,想休息一會,就這樣吧

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

新聞標題:android中顯示意圖和隱式意圖(附帶實現(xiàn)打電話)-創(chuàng)新互聯(lián)
本文地址:http://muchs.cn/article44/ddppee.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、ChatGPT、做網(wǎng)站、網(wǎng)站制作、品牌網(wǎng)站制作、手機網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設網(wǎng)站維護公司