相关疑难解决方法(0)

如何在Android上实现我自己的URI方案

假设我想定义一个URI,例如:

myapp://path/to/what/i/want?d=This%20is%20a%20test
Run Code Online (Sandbox Code Playgroud)

必须由我自己的应用程序或服务处理.请注意,该方案"myapp",而不是"http",或"ftp".这正是我的意图:为Android OS全局定义自己的URI架构.这可能吗?

这有点类似于某些程序已经在做的事情,例如Windows系统,例如Skype(skype://)或任何torrent下载程序(torrent://).

browser android uri intentfilter android-intent

159
推荐指数
5
解决办法
17万
查看次数

OAuth和自定义方案会在Chrome中生成"ERR_UNKNOWN_URL_SCHEME"

我已经坚持了好几个小时,因为之前的事情正在发挥作用,但突然停止了,表现得像预期的那样.我真的不知道如何以及为什么我在这个过程中重新检查每一行代码而不能看到什么是错的,所以我要求你们帮忙.

好的.所以我LoginScreen有一个按钮开始新Intent.ACTION_VIEW的点击活动.这将在浏览器中启动OAUTH进程,并ApiManager.OAUTH_CALLBACK_URI设置为stjapp://oauthresponse.

这是我AndroidManifest.xml参与此活动的部分:

<activity
    android:name=".LoginScreen"
    android:label="@string/application"
    android:launchMode="singleTask">
    <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="stjapp" android:host="oauthresponse" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

我如何开始Intent.ACTION_VIEW我的活动:

private View.OnClickListener loginHandler = new View.OnClickListener() {
        public void onClick(View v) {
             OAuthClientRequest request = null;
             try {
                request = OAuthClientRequest
                    .authorizationLocation(ApiManager.OAUTH_AUTHORIZE)
                    .setClientId(ApiManager.CLIENT_ID).setRedirectURI(ApiManager.OAUTH_CALLBACK_URI)
                    .buildQueryMessage();
            } 
            catch (OAuthSystemException e) { e.printStackTrace(); } 
            Intent intent = new Intent(Intent.ACTION_VIEW, …
Run Code Online (Sandbox Code Playgroud)

android android-manifest android-intent

12
推荐指数
1
解决办法
5万
查看次数

与Firebase FCM一起使用本机

我正在尝试通过此文档使用React Native和Firebase实现推送通知.

我在本教程中设置了我需要的设置.

   import React, { Component } from 'react'
import { View } from 'react-native'
import { Input, Text, Button } from '../Components'
import type { RemoteMessage } from 'react-native-firebase'
import firebase from 'react-native-firebase'
import type { Notification, NotificationOpen } from 'react-native-firebase';

export default class TestComponent extends Component {

  async componentDidMount() {
    await this.SetUpAuth();
    await this.SetUpMessaging();
    this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
      // Get the action triggered by the notification being opened
      const action = notificationOpen.action;
      // …
Run Code Online (Sandbox Code Playgroud)

javascript firebase react-native firebase-cloud-messaging

7
推荐指数
1
解决办法
5338
查看次数

从URL启动活动

我试图在用户浏览某个网址时启动我的应用程序.我找到了一些例子,它们在清单中都有相同的东西,但它对我不起作用.我已将intent-filter放在Activity和Receiver下.

这是我的清单片段:

<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:host="www.urbandictionary.com" android:scheme="http"></data>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

在Activity下,我尝试使用onNewIntent,当它在Receiver下时,我尝试使用onReceiveIntent,两者都使用一个简单的Log.i调用来查看它是否被触发.我没有太多运气.

android manifest android-intent android-activity

6
推荐指数
1
解决办法
4417
查看次数

通过浏览器中的 URL 打开 Android 应用程序

好吧,所以我知道还有更多的事情要做。我在这里读过很多答案,它们都说同样的事情,但它对我不起作用。我希望能够使用浏览器中带有自定义 URL 方案的链接打开 Android 应用程序。首先,我使用的是模拟器(实际上是Genymotion),所以我不知道这是否与它有关。我看到的答案一直说我所需要的只是与此类似的东西:

<intent-filter>
    <data android:scheme="myapp" android:host="hello"/>
    <action android:name="ANDROID.INTENT.ACTION.VIEW"/>
    <category android:name="ANDROID.INTENT.CATEGORY.BROWSABLE"/>
    <category android:name="ANDROID.INTENT.CATEGORY.DEFAULT"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

我把它放在一个新的空白活动上,而不是主要活动上。

如果我理解正确的话,任何以 开头的 URLmyapp://hello都会使用该意图过滤器打开活动。但是,无论我尝试什么,我都会在浏览器中收到 ERR_UNKNOWN_URL_SCHEME。这是原生的 Android 浏览器,因为我无法将 Chrome 安装在 Genymotion 上(至少免费版本不行)。这是需要 Chrome 的东西吗?这是只能在实际设备上完成的事情吗?我做错了什么吗?

android intentfilter

5
推荐指数
1
解决办法
2万
查看次数