小编Mat*_*ini的帖子

在Android上,我可以注册一个回调,告诉我蓝牙是打开还是关闭?

我需要在我的应用程序内部了解蓝牙是打开还是关闭.或者,如果从操作系统设置下拉菜单打开或关闭蓝牙.我以为我可以在活动中做到这一点onResume().但事实证明,当Android操作系统的设置"下拉菜单"(通过用手指从屏幕的上边缘拉下来访问的菜单)打开时,活动不会暂停.

当蓝牙可用或不可用时,我需要更新我的UI.

我可以注册回拨(例如a BroadcastReceiver)或任何其他回调,让系统告诉我蓝牙可用性何时发生变化?

android bluetooth android-lifecycle android-activity

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

打开图像,意图来自内部存储

我想在Nexus 7平板电脑上使用Android默认图像查看器打开内部文件夹中的图像.我使用以下代码,但由于某种原因,图像不会显示.我做错了什么?该文件的路径是:

file:///data/data/com.example.denandroidapp/files/Attachments/photoTemp/photo.jpg
Run Code Online (Sandbox Code Playgroud)

(这是Uri.parse("file://"+ file)返回的内容).

ArticlePhoto photo =  new ArticlePhoto(soapObject);
File f = new File(context.getFilesDir() + "/Attachments/photoTemp");

if(!f.exists())
    f.mkdirs();

if (photo.ArtPhoto != null) {
    Bitmap articlePhoto = BitmapFactory.decodeByteArray(photo.ArtPhoto, 0, photo.ArtPhoto.length);                      
    ByteArrayOutputStream  bytesFile  =  new ByteArrayOutputStream();
    articlePhoto.compress(Bitmap.CompressFormat.JPEG, 100, bytesFile);

    File file = new File(f + "/photo.jpeg");

    try {
        if(!file.exists())
            file.createNewFile();

        FileOutputStream outStream =  new FileOutputStream(file);

        outStream.write(bytesFile.toByteArray());                  
        outStream.close();

        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse("file://" + file),"image/jpeg"); 
        startActivity(intent);

    } catch(Exception ex) {
        AlertDialog alert =  new  AlertDialog.Builder(context).create();
        alert.setTitle("Warning!");
        alert.setMessage(ex.getMessage());
        alert.show();
    }
}
Run Code Online (Sandbox Code Playgroud)

android

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

为什么我的FragmentTransacton()或FragmentManager.beginTransaction()会遇到空指针异常

我收到了nullPointerException:

java.lang.RuntimeException: Unable to start activity ComponentInfo{---private---}: 
      java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.app.FragmentTransaction 
      android.support.v4.app.FragmentManager.beginTransaction()' on a null object reference
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.support.v4.app.FragmentTransaction 
      android.support.v4.app.FragmentManager.beginTransaction()' on a null object reference
            at com.zero. ??? .BoxFragment.newInstance(BoxFragment.java:59)
            at com.zero. ??? .MainActivity$SectionPagerAdapter.getItem(MainActivity.java:111)
            at com.zero. ??? .MainActivity.onCreate(MainActivity.java:58)
            at android.app.Activity.performCreate(Activity.java:5937)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144) …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception

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

Android:使用FLAG_SECURE时更改窗口背景的颜色

我有一个请求,当我的Android应用程序放入后台时,我将屏幕空白以隐藏敏感数据.这很容易实现使用:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
Run Code Online (Sandbox Code Playgroud)

困难的部分似乎正在改变在后台查看应用程序时获得的空白屏幕的颜色.默认情况下,它似乎是白色的,我似乎找不到覆盖它的方法.有人有主意吗?

android

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

尝试删除 Android Realm 文件,但出现异常

我正在尝试删除 Realm 文件以在用户注销时清除缓存。

这是我正在尝试的:

Realm realm = Realm.getInstance(activity);

realm.close();
RealmConfiguration config = realm.getConfiguration();

Realm.deleteRealm(config);
Run Code Online (Sandbox Code Playgroud)

我得到这个例外:

11-05 23:56:00.902 27521-27521/com.my.app E/AndroidRuntime: java.lang.IllegalStateException: It's not allowed to delete the file associated with an open Realm. Remember to close() all the instances of the Realm before deleting its file.
11-05 23:56:00.902 27521-27521/com.my.app E/AndroidRuntime:     at io.realm.Realm.deleteRealm(Realm.java:1726)
Run Code Online (Sandbox Code Playgroud)

我显然正在关闭某些东西,但它说更多是开放的?我如何关闭所有领域,以便我可以吹掉所有东西并重新开始?

android realm

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

Android adb 的 Windows 源代码在哪里?

我正在尝试了解 Android 如何adb.exe在 Windows 上运行。我找到了以下源代码分支:

https://android.googlesource.com/platform/system/core/+/master/adb/

然而,快速浏览一下该adb.cpp文件,这似乎是 Linux 分支。Windows 版本在哪里?(还是我错了?)

PS:有关如何浏览android.googlesource.com 的信息也将受到赞赏。

windows android adb

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

支持Android TV并重用main Activity

我有一个希望 Android TV 支持的应用程序(该应用程序目前支持手机和平板电脑)

主要活动非常基本,虽然它确实有两个文本输入(用于帐户登录),但我确信它可以在 Android TV 上使用(似乎可以在模拟器上运行,但尚未在真正的 Android TV 上进行测试)。

那么在这种情况下,在我的清单中,我应该为 和 设定一个意图LAUNCHERLEANBACK_LAUNCHER

或者我应该设定意图LEANBACK_LAUNCHER

android android-intent android-tv

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

如何在Android中设置ListView选定项的Alternet文本颜色

我有一个带有imageview和textview的自定义listview。我想当用户选择一个项目时,textview颜色应该更改,而所有其他textview应该保留默认值。

这是我的XML

ListView.xml

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

    <ListView
        android:id="@+id/listViewBell"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:cacheColorHint="#00000000"
        android:choiceMode="singleChoice"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

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

ListViewItems.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dip" >

    <TextView
        android:id="@+id/txt_bell_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/rihanna_love_the_way_lie"
        android:textColor="@color/black"
        android:textSize="15sp"
        android:textStyle="bold"
        android:typeface="sans" />

    <ImageView
        android:id="@+id/list_bell_image"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:src="@drawable/bronze_bell" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

android android-listview

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

使用swipeRefreshLayout更新自定义适配器中的数据

我正在尝试使用swipeRefreshLayout更新数据,但每次向下滑动以刷新它都会重复旧的而不是显示新数据.

你可以帮我解决这个问题并告诉我我在哪里弄错了以及如何解决它.

片段中的代码:

public class StoriesFragment extends Fragment {

    private static final String TAG = MainActivity.class.getSimpleName();

    private static final String url = "http://sho3a3.net/storiesfeed.json";

    private ProgressDialog pDialog;
    private List<StoriesItem> storiesListItem = new ArrayList<StoriesItem>();
    private ListView storiesListView;
    private CustomListAdapter adapter;

    private SwipeRefreshLayout swipeRefreshLayout;

    public StoriesFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.stories_fragment, container, false);

        /*Swipe Refresh Layout*/

        swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container); …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-volley android-json

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

Gradle无法在Android Studio中解析材质对话框依赖项

我正在尝试构建从Git存储库导入的Android应用程序.这个相同的应用程序在另一个环境中正确构建,但在我的环境中,我收到以下错误:

Error:(41, 13) Failed to resolve: com.afollestad:material-dialogs:0.7.7.0
Run Code Online (Sandbox Code Playgroud)

我的build.gradle:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 22
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "my.app.id"
        minSdkVersion 16
        targetSdkVersion 22
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0' …
Run Code Online (Sandbox Code Playgroud)

android gradle android-gradle-plugin material-design

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