小编Bug*_*pen的帖子

Android:decodeFile始终为内部存储中的文件返回null

我有一个文件本地保存到应用程序的私有存储中.我已经验证它存在,但每当我调用BitmapFactory.decodeFile时它总是返回null.

如果我将文件保存为资源并使用ImageView setImageResource,它总是显示正常.

问题是什么?

这是片段:

filename = "test.png";

if (doesFileExist(filename))
    Bitmap bMap = BitmapFactory.decodeFile(filename);
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

Bitmap bMap = BitmapFactory.decodeFile(getFilesDir().getPath()
                    + filename);
Run Code Online (Sandbox Code Playgroud)

android bitmapfactory

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

如何将EXIF元数据附加到Android中的序列化位图?

在Android中,当从手机上的照片解码位图时,原始中的EXIF数据会丢失.我通过套接字将此Bitmap发送到我的服务器,并希望将丢失的EXIF数据重新附加到正在发送的数据.

我有一些代码从MediaStore加载一个Bitmap对象并将其压缩为一个字节数组,以准备通过套接字发送它:

Bitmap bitmap = ...
ByteArrayOutputStream stream = new ByteArrayOutputStream(bitmap);
bitmap.compress(CompressFormat.JPEG, 70, stream);
byte[] input = stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)

我想使用ExifInterface来获取SD卡上原始jpeg中的EXIF元数据,并以某种方式将其添加到传出的字节数组中,以便我能够在服务器上提取具有所有正确EXIF的jpeg (希望不在服务器上这样做).到目前为止,我设法使用ExifInterface读取所有EXIF数据:

String path = ... //bitmap file path
ExifInterface exif = new ExifInterface(path);
... = exif.getAttribute(...)
Run Code Online (Sandbox Code Playgroud)

编辑:最理想的是,我想找到一个不使用库的解决方案.如果我能得到包含EXIF的原始jpeg的字节数组的索引,并将这些字节前置/附加到由此产生的字节数组中,Bitmap那将是最好的.

android exif

17
推荐指数
1
解决办法
8305
查看次数

AsyncTask和Thread之间的真正区别

我一直在阅读关于此事的Android文档(AsyncTask,Thread)和vogella教程,但我还有疑问.

例如,我想从Android应用程序向服务器发送消息.我希望这个过程能够做出回应.我该怎么用?

我已经看到了他们Thread为非阻止UI 创建新的示例,但是这样我们没有进程的进度,你也必须处理响应,Thread因为该run()方法没有返回任何东西.

AsyncTask似乎比较好的选择Thread,但我不知道使用a AsyncTask而不是a 的后果是什么Thread.

multithreading android android-asynctask asynctaskloader difference

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

Android警报对话框在Lollipop上未正确设置样式

我已经尝试了一切来使这个工作,但无法搞清楚.

我试图在我的应用程序中使用警报对话框.它适用于KitKat,但不适用于Lollipop.

我甚至尝试在GitHub上使用许多材料对话框,然后他们再次在Kitkat上工作,但在Lollipop上却没有.

我正在使用库存nexus工厂映像测试我的Nexus 5.

KITKAT与GITHUB材料对话

在此输入图像描述

KITKAT与股票警报对话

在此输入图像描述

LOLLIPOP与GITHUB材料对话

在此输入图像描述

LOLLIPOP与股票警报对话

在此输入图像描述

这也就是github上安装在同一设备上的库,它不能正常工作.所以关于我的应用程序的东西导致了这一点.会是什么呢

在此输入图像描述

android material-design android-5.0-lollipop

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

onLowMemory如何在android上运行?

我想知道onLowMemory()函数是如何执行的

例如.

假设我有3个活动,每个活动都onLowMemory()覆盖了它们的功能,以清理RAM中的数据.我还有一个Application类,它也会覆盖onLowMemory()清理一些全局状态数据.

现在假设我们从活动A - >活动B - >活动C开始,在活动C上我们耗尽内存.我的问题是那之后会发生什么?

根据我的理解,onLowMemory()Activity C和Application类的功能将被调用,我是否正确?onLowMemory()活动A和B的功能是否被调用?

此外,我相信活动A和B将被杀死(因为它们是后台活动),但在这些活动被杀之前,它们各自onLowMemory()被召唤?

android

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

IntentService的StartForeground

我有一个IntentService,我希望通过持续通知使其变得粘稠.问题是通知出现然后立即消失.该服务继续运行.我startForeground()IntentService怎么用?

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Notification notification = new Notification(R.drawable.marker, "Notification service is running",
            System.currentTimeMillis());
    Intent notificationIntent = new Intent(this, DashboardActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
        Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(this, "App",
            "Notification service is running", pendingIntent);
    notification.flags|=Notification.FLAG_NO_CLEAR;
    startForeground(1337, notification);
    return START_STICKY;
}

@Override
protected void onHandleIntent(Intent intent) {

    String id = intent.getStringExtra(ID);
    WebSocketConnectConfig config = new WebSocketConnectConfig();
    try {
        config.setUrl(new URI("ws://" + App.NET_ADDRESS
                + …
Run Code Online (Sandbox Code Playgroud)

android intentservice foreground-service

12
推荐指数
2
解决办法
8300
查看次数

Android-列表视图中的相邻按钮会自动单击

我正在开发一个填充购物车的模块.我使用ListView并扩展BaseAdapter来填充购物车项目.对于每个项目ListView,我嵌入了两个按钮(inc和dec)来增加和减少购物车中的商品数量.

ListView 已正确更新,但快速单击/点击时的递增/递减按钮显示突然行为.

每当我快速点击任何inc或dec按钮时,将ListView自动点击当前项目旁边的项目的相应inc或dec按钮(以及当前项目btn).

换句话说,每当我快速点击第i个项目的ListViewinc btn时,ListView会自动点击第i + 1个项目的inc btn(以及第i个项目的inc btn).

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.list_item_cart, parent, false);
        holder = new ViewHolder();
        holder.baseItem = (TextView) convertView.findViewById(R.id.qnt_tv);
        holder.qntInc = (TextView) convertView.findViewById(R.id.inc_btn);
        holder.qntDec = (TextView) convertView.findViewById(R.id.dec_btn);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    final CartModel cm = mCart.get(position);
    holder.baseItem.setText(cm.getmTitle());
    holder.qntSel.setText(String.valueOf(cm.getmQnt()));
    holder.qntInc.setOnClickListener(new View.OnClickListener() {
        @Override …
Run Code Online (Sandbox Code Playgroud)

android listview

12
推荐指数
2
解决办法
865
查看次数

如何从FragmentPagerAdapter中删除片段?

我知道这里有一些关于这方面的话题,但我找不到一个可以为我的案子工作的解决方案.

我有一个使用自定义的工作滑动图库FragmentActivity,FragmentPagerAdapter其中包含碎片列表.

在内FragmentActivity是一个ImageView"删除".如果单击,deleteMedia()则调用该函数,然后应删除当前值,FragmentFragment显示以下内容.在我的例子中我该如何做到这一点?

FragmentActivity:

public class GalleryPagerActivity extends FragmentActivity implements OnClickListener {

    private Intent intent;
    private SharedPreferences settings;
    private PagerAdapter mPagerAdapter;
    private ViewPager mPager;
    private List<Fragment> fragments;
    private List<WhiteboardMedia> wiList;

    private int selectedPosition;
    private LinearLayout llTop;
    private TextView tvTop;
    private ImageView delete;
    private ImageView share;
    private TextView tvCounter;
    private TextView tvFilename;
    private TextView tvFilesize;
    private TextView tvDate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try { …
Run Code Online (Sandbox Code Playgroud)

android android-fragments fragmentpageradapter android-fragmentactivity

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

如何使用javascript更改HTML文本字段的值

<head>
<script type="javascript">
function display()
    {
        document.getElementById("textField1").value = "abc";
    }
</script>
</head>
<body>

<form id="form1" action="http://google.com">

<input id="textField1" type="text" value="0" align="right" size="13"/><br>

<input id="button1" type="button" value="1" onclick="display()">
</form>
</body>
Run Code Online (Sandbox Code Playgroud)

但是textfield的值并没有改变.

任何想法我做错了什么?

html javascript forms

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

ScrollView中没有释放动力

在我的活动中,我有两个RecyclerViews ScrollView.问题是当我轻扫/轻弹时ScrollView,滚动立即停止.是否有办法ScrollView实现动量或惯性,所以在滚动停止之前有一些减速?

我的XML如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ProgressBar
    android:id="@+id/threadload_progress"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:visibility="gone" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/subforums"
        android:name="net.polunom.forum.fragments.ThreadFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="LinearLayoutManager"
        tools:context=".fragments.ThreadFragment"
        tools:listitem="@layout/fragment_subforum"/>

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/threadlist"
        android:name="net.polunom.forum.fragments.ThreadFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layoutManager="LinearLayoutManager"
        tools:context=".fragments.ThreadFragment"
        tools:listitem="@layout/fragment_thread"/>

</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

android scrollview

10
推荐指数
1
解决办法
1886
查看次数