开发者

Launch (and install) android application from android browser

I want to add button to our mobile web application, which allows user to launch our android application.

As I dont know if application is already installed on device, I need:


You cannot force an install upon a user.

The closest you can get is to have an activity in your application have an <intent-filter> that maps to a URL on your Web site:

    <activity android:name="URLHandler"
              android:label="@string/app_name">
        <intent-filter android:label="@string/app_name">
          <action android:name="android.intent.action.VIEW" />
          <data android:scheme="http"
                android:host="commonsware.com"
                android:path="/whatever"
          />
          <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>

Then, on your Web app, have a link to that URL. When the user clicks the link, on devices that have your app installed, your designated activity will open. On devices that do not have your app installed, the user will be taken to your designated Web page, where you can prompt them with instructions on how to download and install your app.


if (v.getId() == R.id.ImageButton01) {

        if (keyCode == KeyEvent.KEYCODE_ENTER) {


             Toast.makeText(this, "Application Name", Toast.LENGTH_LONG).show();
            Intent i = new Intent();

            i.setAction(Intent.ACTION_VIEW);

            i.setClassName("com.xxx.your_package_name",
                    "com.xxx.your_class_name");

            startActivity(i);

        }
    }  

try {

startActivity(intent);

}

catch (ActivityNotFoundException e) { Toast.makeText(OpenPdf.this,

    "No Application Available to View PDF",

    Toast.LENGTH_SHORT).show();

//connect to given path for downloadinng //use activitynot found exception to catch if not installed and give user the path of //your downloadable file some thing l }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜