android之從第三方啟動自己的apk

來源:互聯網
上載者:User

標籤:

本篇主要是看完郭霖大神在裡的一篇文章後的實驗

貼上大神的文章地址:http://mp.weixin.qq.com/s?__biz=MzA5MzI3NjE2MA==&mid=2650235870&idx=1&sn=8499e45b52199e739d73ba7d2db2c21b&scene=0#wechat_redirect

講的是從網頁的串連開啟自己的應用,想著用手機搭建一個伺服器,使用 KSWEB開原始伺服器 ,無奈沒有成功。

1. 用apk啟動另一個apk:(兩個單獨的應用)

代碼主要需要要啟動的應用的完整包名和完整類名,通過發送Intent傳遞訊息

// 由一個應用啟動另一個應用 需要 package名稱跟class名稱        Intent mIntent = new Intent( );        mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        ComponentName comp = new ComponentName("com.cl.slack.deeplinks", "com.cl.slack.deeplinks.MainActivity");        mIntent.setComponent(comp);        mIntent.setAction("android.intent.action.VIEW");        startActivity(mIntent);        finish();

2. 對自己也是醉了,最後居然是使用tomcat搭建了一個區域網路伺服器,然後虛擬機器開啟區域網路地址,哈哈,但是我也是實現了大神的功能,在網頁裡開啟自己的app



網頁端就一句話

<a href="com.slack.androidtest://buydress">deep link</a>
manifest檔案:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="android.addre.com.deeplinks" >    <application        android:allowBackup="true"        android:icon="@mipmap/ic_launcher"        android:label="@string/app_name"        android:supportsRtl="true"        android:theme="@style/AppTheme" >        <activity android:name=".MainActivity" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />                // deep links                <action android:name="android.intent.action.VIEW" />                <category android:name="android.intent.category.DEFAULT" />                <category android:name="android.intent.category.BROWSABLE" />                <data android:scheme="com.slack.androidtest" />            </intent-filter>        </activity>        <activity android:name=".BuyActivity" >        </activity>    </application></manifest>
預設啟動的activity:

/** deep links * 參考郭霖文章:http://mp.weixin.qq.com/s?__biz=MzA5MzI3NjE2MA==&mid=2650235870&idx=1&sn=8499e45b52199e739d73ba7d2db2c21b&scene=0#wechat_redirect * create by chenling 2016-05-10 * */public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        Intent intent = getIntent();        if (intent != null) {            Uri uri = intent.getData();            if(uri != null){                // uri  com.slack.androidtest://buydress                Log.i("slack",uri.toString());                String host = uri.getHost();                Log.i("slack",host);                if ("buydress".equals(host)) {                    // 跳轉到賣裙子介面                    startActivity(new Intent(this,BuyActivity.class));                }            }        }    }}
感謝郭霖大神


android之從第三方啟動自己的apk

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.