在我的应用程序中,我所有屏幕的第一个视图是EditText,因此每次进入屏幕时,屏幕键盘都会弹出.如何禁用此弹出窗口并在手动单击EditText时启用它?
eT = (EditText) findViewById(R.id.searchAutoCompleteTextView_feed);
eT.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(eT.getWindowToken(), 0);
}
}
});
Run Code Online (Sandbox Code Playgroud)
xml代码:
<ImageView
android:id="@+id/feedPageLogo"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/wic_logo_small" />
<Button
android:id="@+id/goButton_feed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/go" />
<EditText
android:id="@+id/searchAutoCompleteTextView_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/goButton_feed"
android:layout_toRightOf="@id/feedPageLogo"
android:hint="@string/search" />
<TextView
android:id="@+id/feedLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/feedPageLogo"
android:gravity="center_vertical|center_horizontal"
android:text="@string/feed"
android:textColor="@color/white" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ButtonsLayout_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/feedButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/feed"
android:textColor="@color/black" />
<Button
android:id="@+id/iWantButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1" …Run Code Online (Sandbox Code Playgroud) 一个ListView在我的应用程序有很多字符串元素,如name,experience,date of joining,等我只是想name大胆.所有字符串元素都在一个单独的元素中TextView.
我的XML:
<ImageView
android:id="@+id/logo"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp" >
</ImageView>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/logo"
android:padding="5dp"
android:textSize="12dp" >
</TextView>
Run Code Online (Sandbox Code Playgroud)
我的代码设置ListView项的TextView:
holder.text.setText(name + "\n" + expirience + " " + dateOfJoininf);
Run Code Online (Sandbox Code Playgroud) 我收到此错误:
06-06 10:45:19.685: E/AndroidRuntime(554): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.Android.myApp/com.Android.myApp.Facebook.Example}; have you declared this activity in your AndroidManifest.xml?
Run Code Online (Sandbox Code Playgroud)
但我已经在我的清单文件中声明了它.可能是这种例外的其他原因是什么?
我的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Android.myApp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light" >
<activity
android:name=".SignUpActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SignInActivity"
android:label="@string/app_name" />
<activity
android:name=".HomeActivity"
android:label="@string/app_name" />
<activity
android:name=".selectCityActivity" …Run Code Online (Sandbox Code Playgroud) 我想下载从Dropbox下载的图像并将其缓存以供进一步使用:
String cachePath = mContext.getCacheDir().getAbsolutePath() + entry.fileName();
File cacheFile = new File(cachePath);
//cacheFile.exists() returns true after 1st call
if(!cacheFile.exists()){
//If cache doesn't exist, download the file
mFos = new FileOutputStream(cachePath);
mApi.getThumbnail(path, mFos, ThumbSize.BESTFIT_320x240,
ThumbFormat.JPEG, null);
}
mDrawable = Drawable.createFromPath(cachePath);
mImageView.setImageDrawable(mDrawable);
Run Code Online (Sandbox Code Playgroud)
的mDrawable是null如果代码不进入if块.
如果我评论if条件它工作正常.但每次下载图像.
编辑:
以上代码来自如何测试缓存中的文件
在我的应用程序中,我有一个调用摄像头的button1,在捕获图像后,它必须保存到设备库中.当我点击button2时,它必须打开图库,并要求选择图片.选中后,必须在这些按钮下方的imageView上显示.
这是我的代码:
package com.android.imageuploading;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class ImageUploadingActivity extends Activity {
private static final int REQUEST_CODE = 1;
private Bitmap bitmap;
private ImageView imageView;
private Button button_1;
public int TAKE_PICTURE = 1;
private Button button_2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) …Run Code Online (Sandbox Code Playgroud) 我的XML:
<AutoCompleteTextView
android:id="@+id/searchAutoCompleteTextView_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:completionThreshold="2"
android:hint="@string/search" />
Run Code Online (Sandbox Code Playgroud)
我的java代码:
AutoCompleteTextView eT = (AutoCompleteTextView)findViewById(R.id.searchAutoCompleteTextView_feed);
eT.addTextChangedListener(this);
String[] sa = new String[]{"apple", "mango", "banana", "apple mango", "mango banana"};
ArrayAdapter<String> aAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, sa);
eT.setAdapter(aAdapter);
Run Code Online (Sandbox Code Playgroud)
这不起作用....我的意思是它只是像EditTextView一样工作.我哪里错了?
完整代码:
public class FeedListViewActivity extends ListActivity implements TextWatcher{
private AutoCompleteTextView eT;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.feed);
eT = (AutoCompleteTextView) findViewById(R.id.searchAutoCompleteTextView_feed);
eT.addTextChangedListener(this);
Thread thread = new Thread(null, loadMoreListItems);
thread.start();
}
private Runnable returnRes = new Runnable() {
public void run() {
//code for other purposes …Run Code Online (Sandbox Code Playgroud) 我的片段中有一个广播接收器,用于跟踪任何新收到的短信.
private BroadcastReceiver smsBroadcastReceiver;
IntentFilter filter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
smsBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("smsBroadcastReceiver", "onReceive");
}
};
}
@Override
public void onStart() {
super.onStart();
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(smsBroadcastReceiver, filter);
}
@Override
public void onStop() {
super.onStop();
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(smsBroadcastReceiver);
}
Run Code Online (Sandbox Code Playgroud)
和Manifest中的权限:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
Run Code Online (Sandbox Code Playgroud)
问题是我从来没有得到日志Log.e("smsBroadcastReceiver", "onReceive");
我肯定得到短信,而接收器仍然注册.
但是,如果我将接收器作为一个单独的类编写并将其放入Manifest中,则调用onReceive().
我错过了什么?
我正在尝试将Salesforce Mobile SDK用于原生Android.需求:
- 允许任何拥有Salesforce帐户的用户登录
- 获取他/她的联系人列表
- 获取特定联系人详细信息
如果这些不属于Mobile SDK,请告知我们.
我关注https://github.com/forcedotcom/SalesforceMobileSDK-Android:
- 克隆它
- 安装NPM并安装所需的子模块
- 使用原生的forceroid创建了一个新的Android应用程序
bootconfig.xml使用我连接的应用程序的值更改了值.
它记录正常,但当我尝试获取联系人时,它说:
未为此组织启用Rest API
登录响应似乎没问题.客户端对象json凭据:
{
"clientId": "*******",
"loginUrl": "https://login.salesforce.com",
"identityUrl": "https://login.salesforce.com/id/99VVHJHGF5688/00548000003yOKeAAM",
"instanceUrl": "https://ap2.salesforce.com",
"userId": "**********",
"orgId": "*********",
"communityUrl": null,
"refreshToken": "*************",
"accessToken": "************",
"communityId": null,
"userAgent": "SalesforceMobileSDK/4.3.0 android mobile/7.0 (Nexus 6P) SFTest/1.0 Native uid_32aea9bdde1b8b7e"
}
Run Code Online (Sandbox Code Playgroud)
编辑1:获取联系人列表的代码:
public void onFetchContactsClick(View v) throws UnsupportedEncodingException {
sendRequest("SELECT Name FROM Contact");
}
private void sendRequest(String soql) throws UnsupportedEncodingException {
RestRequest restRequest = RestRequest.getRequestForQuery(ApiVersionStrings.getVersionNumber(this), soql);
client.sendAsync(restRequest, new AsyncRequestCallback() …Run Code Online (Sandbox Code Playgroud) 我想从网址下载文本文件并将其保存在设备本地,并在我的应用中使用它.
码:
try {
File file = new File(getFilesDir(), "file.txt");
if (file.length() > 0) {
//File already exists and it is not empty
return;
}
URL url = new URL("https://www.abc.com/file.txt");
FileOutputStream fos = new FileOutputStream(file);
InputStream in = url.openStream();
byte[] buffer = new byte[1024];
int length = 0;
while ((length = in.read(buffer)) > 0) {
fos.write(buffer, 0, length);
}
fos.flush();
fos.close();
} catch (Exception e) {
// TODO:
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,代码依赖于getFilesDir()假设始终存在.但是,通过适当的网络连接和权限,几乎没有问题:
getFilesDir()在任何情况下我都会失败吗?编辑: 当我尝试读取我在logcat中显示的下载文件(有时会发生在10中)时,我得到的内容是:

用于读取文件的代码:
BufferedReader …Run Code Online (Sandbox Code Playgroud) 使用Huawei App Links时(因为Firebase动态链接不适用于Huawei App Gallery),生成的就是这种长链接。
当在未安装我的应用程序的 Android(Google) 设备上单击此链接时,我会看到以下选项:
“打开”-在浏览器中打开深层链接,即https://example.com/referral/3c3432x
“下载”- 使用我的应用程序页面打开 Google Play 商店应用程序
下载行为很好,但我不想要打开行为,因为该链接实际上不存在。据我所知,仍然可以在桌面上访问此链接,并且可能会尝试在浏览器上访问该链接,但目前我们可以在这种情况下显示 404。
有没有办法避免“打开”选项?或者更好的是停止显示此屏幕并立即重定向到应用程序(如果已安装)或播放商店(未安装)。就像 Firebase 的做法一样。
我什至尝试了这里列出的landing_page_type=2选项:https: //developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-applinking-createlinks-define-0000001055514692但这并没有似乎不起作用,它总是显示打开/下载页面,无论值如何。