简体   繁体   中英

how to open an activity with url scheme android

I have two activities.

1.mainactivty.java

2.URL.java

now I would like to open second activity (URL.java) and I get 0 or 1 by using url scheme.

my manifest.xml :

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />    
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.ex18_urlschme.URL"
        >

        <intent-filter >
            <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.VIEW"/>
            <data android:scheme="com.shadyab.shadyab"/>
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>

    </activity>

on a php page :

<button onclick="location.href='com.shadyab.shadyab:/status=0'">click me</button>

(after click on click me ,I want to open URL.java and I get value of status. may be 0 or 1 ).

how can I do ?

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        Intent intent = getIntent();
        if(Intent.ACTION_VIEW.equals(intent.getAction())){
            Uri uri = intent.getData();
            int status = Integer.parseInt(uri.getQueryParameter("status")); // reading status 
            Log.d("TAG","status code " +status);
        }

    }

Hope this helps!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM