小编Hit*_*ahu的帖子

如何在android中获取相机制作的照片的默认目录?

我希望在android中获取相机制作的照片的默认目录.

我认为代码A可以做到这一点,并/storage/sdcard0/DCIM显示在日志中,

但事实上,我的相机拍摄的照片存储在文件夹中 /storage/extSdCard/DCIM

如何在android中获取相机拍摄的照片的默认目录?谢谢!

代码A.

File dir10 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
Log.e("MainActivity", "getExternalStoragePublicDirectory() 10:" + dir10.toString());
Run Code Online (Sandbox Code Playgroud)

更多

看来相机拍摄的照片的默认存储位置是由用户设置的,有时是存储卡,有时是SD卡.我希望知道用户为相机制作的商店照片选择了哪个存储位置.

在此输入图像描述

camera android android-sdcard

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

当我在Samsung Knox“硬件访问”上安装并打开示例应用程序时,出现“客户端尚未准备好。”

最近,我正在学习基于三星Knox的Android Studio SDK开发。“硬件访问”是我在其官方网站上下载的示例应用程序。但是,当我尝试在Samsung Phone Galaxy S5上安装时,手机无法打开该应用程序并提示“ Sample2已停止”。Android Studio会打印以下内容:

06/22 08:37:10: Launching app
    No apk changes detected since last installation, skipping installation of C:\workspace\aisino\download-codes\Samsung\Sample2\app\build\outputs\apk\app-debug.apk
    $adb shell am force-stop           com.samsung.android.sdk.b2b.samples.cSDKsample2
    $adb shell am start -n "com.samsung.android.sdk.b2b.samples.cSDKsample2/com.samsung.android.sdk.b2b.samples.cSDKsample2.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Client not ready yet..
Run Code Online (Sandbox Code Playgroud)

android android-studio samsung-knox

5
推荐指数
0
解决办法
846
查看次数

在没有互联网连接的情况下进入应用程序后,facebook 或 instagram 应用程序如何保留图像或数据?

例如,在 Facebook 应用程序中,我使用互联网连接登录。然后我关闭应用程序,关闭互联网并关闭我所有的系统选项卡。然后即使我的互联网连接关闭,我看到之前加载的图像和数据仍然保留。

Facebook 应用程序如何做到这一点?如果想在我的 Android 应用程序中实现这样的功能,我该怎么办?

android offline-caching

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

保留退格键不会一一清除文本

我有一个EditText实现TextWatcher,但是Backspace键有问题。按住退格键时,前5个字符被一一清除,但是按住退格键时,转换为图像的后5个字符不能一一清除。

看图片:

在此处输入图片说明

  1. MainActivity.java

    public class MainActivity extends AppCompatActivity {
    Spannable.Factory spannableFactory;
    
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    spannableFactory = Spannable.Factory
            .getInstance();
    
    final EditText editText = (EditText) findViewById(R.id.editText);
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
    
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            editText.removeTextChangedListener(this);
            if (s.length() >= 5) {
                editText.setText(getTextToIcon(getApplicationContext(), s));
            }
            if(count!=0){                               // != key delete
                if (s.length() - 1 > start) {
                    editText.setSelection(start + 1); …
    Run Code Online (Sandbox Code Playgroud)

android backspace android-edittext

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

SharedPreferences :它是一个类还是一个接口?

我很困惑,请帮助我。

Android 开发人员文档SharedPreferences是一个Interface,我们也可以在grepCode上看到SharedPreferences 是一个Interface

developers.android也说SharedPreferences是一个类。

他们写。

“SharedPreferences提供了一个通用框架......”

那么,SharedPreferences 是一个还是一个接口

android sharedpreferences

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

如何在单击后更改回收器视图中的特定图像

我想在Recycler视图中更改单击项目的相应图像.现在发生的事情是,如果我点击第2项图像正在改变列表中的随机项目位置

public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.DataObjectHolder> {

private static String LOG_TAG = "MyRecyclerViewAdapter";
private ArrayList<CRMbean> mDataset;
private static MyClickListener myClickListener;
static Context mContext;
private List<String> mtList ;


public MyRecyclerViewAdapter(List<String> filteredList, CRMactivity crMactivity) {
    mtList = filteredList;

}

public static class DataObjectHolder extends RecyclerView.ViewHolder
        implements View
        .OnClickListener {
    public static ImageView testImage;
    TextView name;
    TextView regId;
    TextView roomNo;

    public DataObjectHolder(View itemView) {
        super(itemView);
        name = (TextView) itemView.findViewById(R.id.name);
        regId = (TextView)itemView.findViewById(R.id.reg_id);
        roomNo = (TextView)itemView.findViewById(R.id.roomno);
         testImage = (ImageView)itemView.findViewById(R.id.logo);


        Log.i(LOG_TAG, "Adding Listener");
        itemView.setOnClickListener(this);
    } …
Run Code Online (Sandbox Code Playgroud)

android uiimageview android-recyclerview

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

如何知道给予firebase数据的随机id

我的问题是我无法检索Firebase保存数据时生成的随机密钥(我不得不使用该随机密钥),例如

在此输入图像描述

我尝试使用dataSnapshot.getKey(),但它没有用,任何帮助将受到高度赞赏.提前致谢

android firebase firebase-realtime-database

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

从 SQLite 迁移到 Android Room Persistence Library

我有一个使用SQLite数据库的应用程序,我试图SQLiteAndroid Room API.我创建的 DAO 类、实体类和 DB替换 Android ,但是在Async任务中执行数据库查询时出现以下错误:

引起:java.lang.IllegalStateException:需要从 3 迁移到 1。请在构建器中提供迁移或在构建器中调用 fallbackToDestructiveMigration 在这种情况下 Room 将重新创建所有表。在 android.arch.persistence.room.RoomOpenHelper.onUpgrade(RoomOpenHelper.java:82) 在 android.arch.persistence.room.RoomOpenHelper.onDowngrade(RoomOpenHelper.java:94) 在 android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper $OpenHelper.onDowngrade(FrameworkSQLiteOpenHelper.java:128) 在 android.database.sqlite.SQLiteOpenHelper。

我无法理解我错过了什么,任何帮助将不胜感激。

sqlite android android-asynctask android-room

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

Android 资源无法找到资源 ID #0x7f070024

这是我第一次遇到这样的问题,我有点傻眼了。我的问题是,每当我调试我的应用程序时,一切都很好,但只要我生成一个 apk 并通过 crashlytics 将它分发给我的 beta 测试人员,所有的地狱都失败了,我被扔了这个Resources$NotFoundExeption

我检查了我的R.java文件中的资源0x7f070024,发现它显示了:

public static final int common_google_play_services_unknown_issue=0x7f070024;
Run Code Online (Sandbox Code Playgroud)

这对我来说意义不大。然后我继续另一个字符串资源错误,它指向资源 ID 0x7f070036,它显示了我:

public static final int app_name=0x7f070036;
Run Code Online (Sandbox Code Playgroud)

我检查了这个变量的用法,我使用这个字符串资源的唯一地方是在AndroidManifest.xml

 <application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"      //**HERE**
    android:theme="@style/AppTheme">
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"/>
    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="blablablah"/>

    <activity
        android:name=".views.activities.LoginActivity"
        android:configChanges="keyboard|keyboardHidden"
        android:screenOrientation="portrait">
        <intent-filter android:label="@string/app_name"> //**HERE**
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

为了完成这个问题,让我添加我的 gradle 文件,因为它们可能对解决这个问题很重要:

compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "helpme.jesus"
    minSdkVersion 16
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

dependencies …
Run Code Online (Sandbox Code Playgroud)

java android android-resources

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

如何在iOS中使用NSUserDafaults保存和检索NSObject类

嗨我想保存和检索NSObject类使用NSUserDefaults我写下面的代码,但我得到如下的异常

由于未捕获的异常' NSInvalidArgumentException' 终止应用程序,原因:'尝试为密钥DATA插入非属性列表对象'

为了节省: -

 SavingBean*savingbean = [[SavingBean alloc]init];
    [savingbean savingData:userName.text :passWord.text];

    NSUserDefaults * defaults = [[NSUserDefaults alloc]init];
    [defaults setObject:savingbean forKey:@"DATA"];
Run Code Online (Sandbox Code Playgroud)

检索: -

defaults = [[NSUserDefaults alloc]init];
savingbean = [defaults objectForKey:@"DATA"];

NSLog(@"Username is===>%@",savingbean.userName);
NSLog(@"Password is===>%@",savingbean.passWord);
Run Code Online (Sandbox Code Playgroud)

ModelClas: -

.h文件: -

#import <Foundation/Foundation.h>


@interface SavingBean : NSObject{

    NSString *userName;
    NSString *passWord;
}

@property(nonatomic, retain) NSString *userName;
@property(nonatomic, retain) NSString *passWord;

-(void)savingData :(NSString*)userName :(NSString*)password;

@end
Run Code Online (Sandbox Code Playgroud)

.m文件: -

#import "SavingBean.h"

@implementation SavingBean
@synthesize userName,passWord;

-(void)savingData :(NSString*)username :(NSString*)password{

    userName …
Run Code Online (Sandbox Code Playgroud)

objective-c nsuserdefaults ios

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

Android:正确的方法来停止,取消绑定并完全删除NotificationListenerService

我有一个从Manifest启动的NotificationListenerService.该服务正在运行并正在处理通知.我想能够停止,取消绑定和删除(onDestroy调用).有人能提供一个最小的例子吗?

我已经尝试过实现ServiceConnection和unbind()和selfstop()但它仍然不会运行onDestroy.我还试图设置内联NotificationListenerService,但无法弄清楚如何绑定它.

service android

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

自定义ListView项中的视图没有主题

问题:

我有一个自定义适配器listview,目前包含checkboxedittext。我没有更改res/values/styles文件夹中的任何主题。由于某种原因,checkboxedittext具有与正常样式/主题(“ AppTheme”)不同的样式/主题。

自动生成的主题:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是该复选框是白色的,只有选中该复选框才能看到。(颜色不是上面设置的colorAccent),并且edittext具有与选中该复选框时相同的颜色(绿色/蓝色)。

颜色:

<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
Run Code Online (Sandbox Code Playgroud)

我尝试了什么?

我尝试使用xml属性android:theme和设置项目容器的主题/样式以及项目本身style。每个都无济于事。

这正常吗?如果是这样,如何更改列表项的样式/主题?如果没有,那可能是错的?

我的listitem.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent" >

<CheckBox
    android:id="@+id/cb_listitem"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"/>

<EditText
    android:id="@+id/editText_listitem"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="9"
    android:textColor="@color/black"/>

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

自定义适配器中的getView:

@Override
public View getView(int position, …
Run Code Online (Sandbox Code Playgroud)

android listview themes android-layout

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

ButterKnife 8.0.1 @OnClick无法在Fragment中工作 - Android Studio

我在我的android studio项目中使用ButterKnife 8.0.1.下面是我的gradle文件和片段类的片段.我无法在按钮点击中看到Toast消息.但是如果我使用onCLicklistener,我可以看到Toast.

请帮我看看我做错了什么我被卡住了

我的Gradle

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "tdd.serveroverload.com.tdd"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.jakewharton:butterknife:8.0.1'
}
Run Code Online (Sandbox Code Playgroud)

片段类

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View calcView = inflater.inflate(R.layout.content_main, container, …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-studio butterknife

0
推荐指数
1
解决办法
5928
查看次数