小编Dan*_*e B的帖子

如何通过Android中的反射实例化一个监听器

我必须为Android 1.6(API 4)开发一个应用程序,该应用程序应该能够在Android 2.2或更高版本的手机中使用OnAudioFocusChangeListener(自Android 2.2-API 8以来可用).

任何人都可以告诉我如何通过反射实例化一个监听器?我已经设法通过反射运行静态和非静态方法,但我不知道如何处理侦听器.

这是反映的倾听者:

AudioManager  audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

OnAudioFocusChangeListener audioListener = new OnAudioFocusChangeListener() {
    @Override
    public void onAudioFocusChange(int focusChange) {
    // code to execute
    }
};

public void getAudioFocus() {
    audioManager.requestAudioFocus(audioListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
}

public void releaseAudioFocus() {
    audioManager.abandonAudioFocus(audioListener);
}
Run Code Online (Sandbox Code Playgroud)

这是我设法通过反射运行的方法的代码示例:

Class BluetoothAdapter = Class.forName("android.bluetooth.BluetoothAdapter");
Method methodGetDefaultAdapter = BluetoothAdapter.getMethod("getDefaultAdapter"); // static method from the BluetoothAdapter class returning a BluetoothAdapter object
Object bluetooth = methodGetDefaultAdapter.invoke(null);
Method methodGetState = bluetooth.getClass().getMethod("getState"); // non-static method executed from the BluetoothAdapter …
Run Code Online (Sandbox Code Playgroud)

java android

8
推荐指数
1
解决办法
3612
查看次数

适用于Firebase的云功能:您可以检测到应用卸载吗?

当用户卸载应用程序时是否可以触发云功能,以便我们可以清理匿名用户实时数据库条目?

firebase firebase-realtime-database google-cloud-functions

8
推荐指数
1
解决办法
1881
查看次数

Firebase Analytics:是否在 iOS 上使用 IDFA?

鉴于即将推出的 iOS 14 权限提示使用 IDFA 标识符的应用程序,我想知道 Firebase Analytics 和 Firebase Auth 是否确实需要访问 IDFA 才能运行。

在这种情况下,我们是否需要在 AppStore 上发布该应用程序时声明该应用程序正在使用 IDFA?

idfa firebase-authentication firebase-analytics ios-permissions ios14

8
推荐指数
1
解决办法
4325
查看次数

使用Upstart管理uWSGI

我正在尝试使用Upstart配置uWSGI.

我创建了文件/etc/init/uwsgi-flask.conf:

description "uwsgi for flask"
start on runlevel [2345]
stop on runlevel [06]
exec /appdir/virtualenvdir/bin/uwsgi /appdir/virtualenvdir/uwsgi.ini --die-on-term
Run Code Online (Sandbox Code Playgroud)

重新启动时,它正确启动,但我无法停止服务.

如果我在shell上输入initctl stop uwsgi-flask,它会给出:

initctl: Unknown instance:
Run Code Online (Sandbox Code Playgroud)

有谁有任何想法?

python upstart uwsgi

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

Swift:如何检测UISplitViewController当前是否显示1个或2个控制器?

如何检测UISplitViewController当前是仅显示1个视图控制器还是在双窗格中,并排显示2个视图控制器

master-detail uisplitviewcontroller ios swift

7
推荐指数
3
解决办法
4343
查看次数

iOS:Google Analytics和AdMob的CocoaPods问题

假设:

当我启动应用程序时,我收到警告:

您已在开发者控制台中启用了AdMob服务,但看起来好像您的Podfile缺少"pod"Google/AdMob"或者您可能需要pod update在项目目录中运行.

然后应用程序崩溃并出现错误:

断言失败:配置Google服务时出错:可选(错误域= com.google.greenhouse代码= -106"缺少预期的子规格."UserInfo = {NSLocalizedFailureReason =某些子规格未安装pod.有关详细信息,请参阅日志.,NSLocalizedDescription =缺少预期subspecs.}):file /myapp/AppDelegate.swift

这个代码由断言行引发,谷歌分析文档说要添加到AppDelegate.swift文件中:

// Configure tracker from GoogleService-Info.plist.
var configureError:NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
Run Code Online (Sandbox Code Playgroud)



我试着替换

pod 'Google-Mobile-Ads-SDK', '~> 7.0'pod 'Google/AdMob'

该应用程序不再崩溃,但我收到警告:

您目前使用的是SDK 7.6.0版.请考虑将SDK更新为最新的SDK版本,以获取最新功能和错误修复


这是我的完整Podfile:

source …
Run Code Online (Sandbox Code Playgroud)

google-analytics admob ios cocoapods swift

7
推荐指数
2
解决办法
5003
查看次数

Swift:通过ID获取UI对象?

在iOS中,是否可以为UI对象分配字符串ID,然后通过该ID在代码中检索它们?

我正在寻找类似Android的东西 findViewById(id)

tags findviewbyid state-restoration swift

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

iOS 11应用提交:“符号文件过多”

我的目标是iOS 11,现在提交该应用程序后,我收到了一封来自Apple的电子邮件,警告为“符号文件过多”。

看起来好像CocoaPods框架已包含在不需要的架构中。

谁能显示正确的设置,以避免在iOS 11上包含不需要的框架?

ios cocoapods arm64 ios11

7
推荐指数
2
解决办法
2550
查看次数

Android:HttpURLConnection不会断开连接

通过运行netstat在服务器上:
直到前几天我可以看到连接是ESTABLISHED只有大约一秒钟,然后它会从列表中消失
NOW:它保持为ESTABLISHED约10秒钟,然后进入FIN_WAIT1FIN_WAIT2

Android代码是一样的,服务器仍然是一样的

某种Android更新可能会改变一些事情吗?

我无法解释它.

我报告下面的代码.该urlConnection.disconnect()被执行,但连接保持在服务器上建立的.

    HttpURLConnection urlConnection = null;
    System.setProperty("http.keepAlive", "false");

    try {
        URL url = new URL(stringUrl);
        urlConnection = (HttpURLConnection) url.openConnection();
        InputStream instream = new BufferedInputStream(urlConnection.getInputStream());
        ...
        instream.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (urlConnection!=null) {
            urlConnection.disconnect();
        }
    }
Run Code Online (Sandbox Code Playgroud)

android netstat keep-alive httpurlconnection

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