android app 與 web 之間的調用

來源:互聯網
上載者:User

標籤:

1 app call web 

package com.fan.test;import java.util.Timer;import java.util.TimerTask;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;public class TestActivity extends Activity {    /** Called when the activity is first created. */    @Override    //執行app時呼叫瀏覽器開啟 baidu    //設定一個定時器,防止不能跳轉    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        final Uri uri = Uri.parse("http://www.baidu.com");                final Intent it = new Intent(Intent.ACTION_VIEW, uri);                        Timer timer = new Timer();        TimerTask task = new TimerTask() {               @Override               public void run() {                startActivity(it); //執行               }              };            timer.schedule(task, 1); //10秒後    }          //返回時自動結束    public void onRestart()    {        super.onRestart();                System.exit(0);    }}


        Button bn = (Button)findViewById(R.id.button1);        bn.setOnClickListener(new OnClickListener() {                        @Override            public void onClick(View v) {                // TODO Auto-generated method stub                                //doLogin(true,true);                //printStringJNI("hello");                                                                final Uri uri = Uri.parse("http://www.baidu.com");                        final Intent it = new Intent(Intent.ACTION_VIEW, uri);                        //不用定時器也行, 不是必須的                Timer timer = new Timer();                TimerTask task = new TimerTask() {                       @Override                       public void run() {                        startActivity(it); //執行                       }                     };                timer.schedule(task, 2000); //10秒後                            }        });

 

 
androidManifest.xml 檔案中加入
<activity android:name=".TestActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="http" /> <data android:scheme="https" /> <data android:scheme="about" /> <data android:scheme="javascript" /> </intent-filter> </activity>

 2 web call app

android app 與 web 之間的調用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.