(不要沉浸在問題的標題的答案是相關的。)這個例子從Android的瀏覽器中啓動我的活動,並顯示第一二送童車形式URL
package com.example.openapp;
import java.util.List;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txt1 = (TextView) findViewById(R.id.textView1);
TextView txt2 = (TextView) findViewById(R.id.textView2);
try{
Uri data = getIntent().getData();
if(data != null){
String scheme = data.getScheme();
String host = data.getHost();
List<String> params = data.getPathSegments();
String first = params.get(0);
String second = params.get(1);
txt1.setText(first);
txt2.setText(second);
}
} catch (Exception e){
}
}
}
您需要在清單中添加這和替換的Android主機機智h你的主機:
<activity
android:name="com.example.openapp.MainActivity"
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>
<data android:scheme="http" android:host="example.com"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
是你的''在你的''? –
Aleadam
2011-04-20 15:45:19
是................. – 2011-04-20 16:09:41
我想知道如何用android:scheme =「http」啓動一個活動,我之前嘗試過沒有成功!:( – Jorgesys 2014-02-07 01:02:12