my app is not displayed when I click on share on browser in lollipop 5.1

安稳与你 提交于 2020-01-15 06:40:45

问题


I am trying to open my app when you click share on any weblink. How can I do it ? Do I need to ad any permission ? I have added the code below but I dont see my app in the share list. How can I get it to work. I really appreciate any help.

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="example.link" >

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <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" />

                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:scheme="http" android:host="*" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Gradle:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "example.link"
        minSdkVersion 22
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

回答1:


You have to add below code to an activity which you want to open while press on share

<intent-filter android:label="Your app Name">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />



回答2:


try using '*' wildcard char for Host field & Path Pattern fields. My Intent filter looks like:

<intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="*"
                android:pathPattern="/*"
                android:scheme="http" />
            <data
                android:host="*"
                android:pathPattern=".*"
                android:scheme="custom" />
        </intent-filter>

With these changes when i click links on any chat apps or browser link, my app pops up in intent choser.



来源:https://stackoverflow.com/questions/32239039/my-app-is-not-displayed-when-i-click-on-share-on-browser-in-lollipop-5-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!