从短信/彩信中启动Android应用程序?

ste*_*eve 17 sms android

是否可以使用从Android消息应用程序(SMS或MMS)中启动的URL启动应用程序?

小智 41

之前的答案不正确.

您可以为活动添加意图过滤器,该活动将"注册"您的应用以处理SMS正文中的超链接.

例如,如果将以下intent添加到application.xml:

<intent-filter>
  <action android:name="android.intent.action.VIEW"></action>
  <category android:name="android.intent.category.DEFAULT"></category>
  <category android:name="android.intent.category.BROWSABLE"></category>
  <data 
    android:scheme="http" 
    android:host="test.com" 
    android:pathPrefix="/myapp">
  </data>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

并且您在身体中发送包含以下内容的SMS消息:

http://test.com/myapp/somedata
Run Code Online (Sandbox Code Playgroud)

您的应用程序将启动,活动将能够作为意图数据的一部分访问URL.

  • 这是一个很好的答案.但是,当我使用此方法时,它还会显示设备上存在的所有浏览器的选项.有没有办法直接打开我的应用程序而不是向用户显示不同的选项? (2认同)

Ume*_*wte 6

另外由@Adam给出答案,

在Android应用程序的情况下有多个intent过滤器,我们必须使用两个.一个用于应用启动器,另一个用于使用短信中的URL启动应用

<activity android:name="com.SomeActivity" adroid:theme="@style/MyTheme"
android:label="@string/app_name"> 
    <!-- For app launcher -->
    <intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
       <category android:name="com.YorAppPackage" />
    </intent-filter>
    <!-- To open app using link -->
    <intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:scheme="http"
              android:host="yourdomain.com"
              android:pathPrefix="/someurlparam">
        </data>
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

现在在你的短信中添加一个类似的URL

http://yourdomain.com/someurlparam
Run Code Online (Sandbox Code Playgroud)

这应该在url点击启动应用程序,并将在android中添加应用程序图标.


Mac*_*rse 3

不,唯一可识别的 URL 是:

  • 网址。
  • 电子邮件地址。
  • 电话号码。
  • 地图地址。

来自TextViewandroid:autoLink XML 属性。