小编ant*_*afe的帖子

BitmapFactory.decodeStream在设置选项时返回null

我有问题BitmapFactory.decodeStream(inputStream).在没有选项的情况下使用它时,它将返回一个图像.但是当我将它与选项一起使用时,.decodeStream(inputStream, null, options)它永远不会返回Bitmaps.

我要做的是在实际加载之前对Bitmap进行下采样以节省内存.我读过一些很好的指南,但都没有使用.decodeStream.

工作很精细

URL url = new URL(sUrl);
HttpURLConnection connection  = (HttpURLConnection) url.openConnection();

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is, null, options);
Run Code Online (Sandbox Code Playgroud)

什么都不行

InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is, null, options);

InputStream is = connection.getInputStream();

Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

BitmapFactory.decodeStream(is, null, options);

Boolean scaleByHeight = Math.abs(options.outHeight - TARGET_HEIGHT) >= Math.abs(options.outWidth - TARGET_WIDTH);

if (options.outHeight * options.outWidth * 2 >= 200*100*2){
    // Load, …
Run Code Online (Sandbox Code Playgroud)

java android image bitmap

87
推荐指数
2
解决办法
6万
查看次数

从Android电子市场安装应用后获取推荐人

我正在尝试注册一个广播接收器,它捕获Android从市场安装应用程序后启动的"com.android.vending.INSTALL_REFERRER"意图.

我在此处详细了解:http://code.google.com/mobile/analytics/docs/android/#referrals

但是,我无法使用Google Analytics,因此我创建了自己的解决方案.我在清单文件中添加了以下内容:

<receiver android:name="com.test.Receiver" android:exported="true">
<intent-filter>
    <action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)

并创建了一个基本的BroadcastReceiver类:

public class Receiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle extras = intent.getExtras();
        String referrerString = extras.getString("referrer");

        Log.w("TEST", "Referrer is: " + referrerString);
    }
}
Run Code Online (Sandbox Code Playgroud)

然而,当安装应用程序时,接收器似乎没有捕获Intent(如果Intent甚至广播?)并且我没有记录输出.

我在某个地方出错了还是市场在安装应用程序时不再启动这些Intent?

android install referrer google-play google-play-services

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

Android:检测用户是否触摸并拖出按钮区域?

在Android中,我们如何检测用户是否触摸按钮并拖出此按钮的区域?

android button gestures

49
推荐指数
4
解决办法
4万
查看次数

27
推荐指数
3
解决办法
2万
查看次数

Android OpenGL ES透明背景

我正在构建一个利用OpenGL的Android应用程序.就目前而言,它的背景GLSurfaceView是由我的代码动态生成的,并作为纹理加载并绘制glDrawTexfOES.这是"OK",但我可以简单地更加流畅显示图像自身的表面(无OpenGL的).有什么方法可以让GLSurfaceView透明的背景?我听说过一些传言说这可以做到setEGLConfigChooser,但我还没有找到任何确认.最后,我想带一个面我画并把GLSurfaceView在它达到一个层次分明的效果.

我知道这是一个棘手的,很可能是不可行的,但任何输入都是值得赞赏的.提前致谢.

android background opengl-es transparent

25
推荐指数
4
解决办法
2万
查看次数

检测是否在Android上安装了Flash并在活动中嵌入了Flash视频

这实际上是一个两部分问题.首先,是否可以检测Android设备上是否安装了Flash?其次,如果已安装,是否可以在活动中显示Flash视频?我认为您必须在Activity中使用WebView小部件来显示Flash内容,而不是像VideoView这样的内容.Flash甚至在WebView小部件中是否受支持,或者仅由实际的浏览器应用程序支持?

flash android android-webview

23
推荐指数
1
解决办法
9063
查看次数

如何知道在Intent.ACTION_SEND中选择了哪个意图?

我想使用Android Intent.ACTION_SEND快速分享内容.所以我有一个像这样的共享列表: 分享意图清单

但我希望为每个操作分享不同的内容,例如:

  • 如果通过电子邮件/ Gmail共享,内容应为"通过电子邮件分享".

  • 如果通过Facebook分享,内容应该是"通过Facebook分享".

那么,有可能这样做吗?

android android-intent

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

SIGSEGV将HTML + Flash加载到WebView中

当我尝试使用带有loadDataWithBaseURL且PluginState设置为PluginState.ON的嵌入式Flash插件(主要是youtube)将HTML加载到WebView时,我收到了SIGSEGV信号.我能用一个简单的测试用例重现错误.请参阅以下代码:

package ians.android2;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebSettings;

public class TestAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    WebView wv = (WebView)findViewById(R.id.webview);
    wv.getSettings().setPluginState(WebSettings.PluginState.ON);

    String html = "";
    html += "<object width=\"620\" height=\"376\">";
    html += "<param name=\"movie\" value=\"http://www.youtube.com/v/C4KdcRHoXOA?fs=1&amp;hl=en_US&amp;rel=0\"></param>";
    html += "<param name=\"allowFullScreen\" value=\"true\"></param>";
    html += "<param name=\"allowscriptaccess\" value=\"always\"></param>";
    html += "<embed src=\"http://www.youtube.com/v/C4KdcRHoXOA?fs=1&amp;hl=en_US&amp;rel=0\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"620\" height=\"376\"></embed>";
    html += "</object>";

    wv.loadDataWithBaseURL("notreal/", html, "text/html", "utf-8", null); …
Run Code Online (Sandbox Code Playgroud)

flash android webview

15
推荐指数
1
解决办法
1275
查看次数

在BLE的connectGatt中哪个正确的autoConnect标志?

我的目标是在蓝牙低功耗设备和手机之间建立自动连接.我按照示例代码找到了该行

// We want to directly connect to the device, so we are setting the autoConnect parameter to false.
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
Run Code Online (Sandbox Code Playgroud)

上面的代码表示false用于自动连接.但是,我在这里找到了API ,它说

BluetoothGatt connectGatt(上下文上下文,布尔autoConnect,BluetoothGattCallback回调,int传输)连接到此设备托管的GATT服务器.

我还尝试了两个标志:true而且false,只有true工作.我使用的是版本> = Android 5.0.代码和API之间有什么不一致吗?哪个标志是正确的?如果我想进行自动连接,是否需要注意?

这是我的代码

public boolean connect(final String address) {
    if (mBluetoothAdapter == null || address == null) {
        Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
        return false;
    }

    // Previously connected device.  Try to reconnect.
    if (mBluetoothDeviceAddress != null && …
Run Code Online (Sandbox Code Playgroud)

android bluetooth bluetooth-lowenergy bluetooth-gatt

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

电鳗后 Gradle 项目同步失败 | 2022.1.1更新

将我的 Android Studio 更新到最新版本后即电鳗 | 2022年1月1日,我在创建新项目后收到“Gradle项目同步失败” 。

错误:

A problem occurred configuring root project 'BIAssignment'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:7.4.0.
     Required by:
         project : > com.android.application:com.android.application.gradle.plugin:7.4.0
         project : > com.android.library:com.android.library.gradle.plugin:7.4.0
      > No matching variant of com.android.tools.build:gradle:7.4.0 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' …
Run Code Online (Sandbox Code Playgroud)

android gradle android-studio android-studio-electric-eel

13
推荐指数
1
解决办法
5670
查看次数