在android系统上创建一个应用,当此应用被启动时,会通知浏览器打开指定链接。例如打开CSDN首页
MainActivity.java
package txyjssr.test
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = Uri.parse(this.getResources().getString(R.string.web_address));
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
finish();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="txyjssr.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name" android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
string.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CSDN</string>
<string name="web_address">http://www.csdn.net/</string>
</resources>
此外还有一种不用写代码的方式,曾经看到过现在忘了,如果哪位大侠知道请告知,谢了