Sol*_*ety 6 android url-scheme
点击链接时我需要打开我的应用程序.为此,我读到我必须使用URL方案.该链接必须具有myapp://参数形式.
我阅读了关于这个主题的每篇文章,但是当我发送一封带有"myapp:// addUser /?id = 22"的电子邮件并且我从chrome(在我的手机上)打开时,它无法点击.
我的清单:
<activity
android:name="com.example.SplashActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<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:scheme="myapp" android:host="com.example"/>
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
我的课:
公共类SplashActivity扩展FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
String id = uri.getQueryParameter("id");
}
}
Run Code Online (Sandbox Code Playgroud)
要测试代码的邮件内容:
myapp://addUser/?id=22
Run Code Online (Sandbox Code Playgroud)
参考链接:
如何通过在Android OS中的浏览器中调用URL来注册一些URL命名空间(myapp://app.start/)来访问您的程序?
https://legacy.madewithmarmalade.com/devnet/forum/custom-url-scheme-primarily-android-3
UPDATE
我认为问题是邮件正文,但我不知道如何测试它.
在你的清单中
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="com.example"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
您定义了 android:host="com.example",因此您应该修改链接 URL :
myapp://addUser/?id=22 //error
myapp://com.example/?id=22 //correct
Run Code Online (Sandbox Code Playgroud)
然后就可以工作了!!
| 归档时间: |
|
| 查看次数: |
5646 次 |
| 最近记录: |