我需要从 android 的 CalenderView 中选择多次日期。任何人都可以帮助我做同样的事情吗?
例子!让我们看看附图。如果我们将图像中的日历视为 android 的 CalenderView,我需要选择从 16 日到 20 日的所有日期。

我正在通过onActivityResult相机传递一个位图.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "picture");
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
startActivityForResult(intent, REQUEST_TAKE_PHOTO);
Run Code Online (Sandbox Code Playgroud)
我可以得到位图:
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mCapturedImageURI);
Run Code Online (Sandbox Code Playgroud)
但是,我注意到图像在某些设备上旋转.在这里搜索帖子后,典型的解决方案似乎通过以下方式获得轮换:
String path = mCapturedImageURI.getPath();
ExifInterface exif = new ExifInterface(path);
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
Run Code Online (Sandbox Code Playgroud)
不幸的是,int rotation即使位图旋转,我总是0.
我也试过这个,当我在设备上已经上传了一张图片但方向仍为0时有效:
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(mCapturedImageURI, orientationColumn, null, null, null);
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Run Code Online (Sandbox Code Playgroud)
有人看到我在这里做错了吗?还是另一种解决方法?
通常,位图与后置摄像头逆时针旋转90度,前置摄像头顺时针旋转90度.在Moto G上运行正常.在Galaxy S3和LG G2上旋转.
我正在以这样的意图显示通知:
Intent intentOpen = new Intent(this, MainActivity.class);
intentOpen.setAction("ACTION_SHOW_BACKUP_FRAGMENT");
intentOpen.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntentOpen = PendingIntent.getActivity(this, 0, intentOpen, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(pendingIntentOpen);
Run Code Online (Sandbox Code Playgroud)
如您所见,该操作设置为"ACTION_SHOW_BACKUP_FRAGMENT",以便当用户单击通知时,我的singleTop MainActivity可以使用来获取onResume()方法中的操作getIntent().getAction()。
为了使它起作用,我必须onNewIntent()像这样实现:
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切顺利,操作已收到,我可以显示备份视图。但是,如果我按下主页按钮,以便应用程序进入后台,然后通过最近的应用程序菜单再次进入该菜单,该onResume()方法将再次被调用,但"ACTION_SHOW_BACKUP_FRAGMENT"操作仍然存在!因此,我无法区分用户是真的单击了通知还是只是恢复应用程序。
我已经尝试使用Intent和PendingIntent标志的组合日志解决问题,但是没有任何效果。setIntent(new Intent());在使用操作后,我也尝试致电,onResume()但在下次我恢复该应用程序时onNewIntent()仍然可以执行"ACTION_SHOW_BACKUP_FRAGMENT"操作。
我该如何解决这个问题?
android android-intent android-notifications android-activity android-pendingintent
我是说这个:

(在单个屏幕截图中看起来不太好,但它比默认的不确定进度要好得多 - 实际上它的形状和动画非常类似于Android L中包含的新"Material"不确定进度,加上它会改变颜色) .
styles.xml19和20平台之间没有差异,虽然有新的styles_micro.xml,但它似乎没有包括这个.
我正在尝试在AppCompat v22.1中使用带有片段的新材料主题对话框.根据Chris Banes的说法,这样做:
只是返回
new AppCompatDialog(getActivity(), getTheme())从onCreateDialog(Bundle).
设置:
public class MyFragment extends DialogFragment
{
public MyFragment() { }
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AppCompatDialog(getActivity(), getTheme());
}
...
}
Run Code Online (Sandbox Code Playgroud)
在正常情况下完美运作; 对话框是正确的主题和一切.但是,当我们尝试显示带有STYLE_NO_TITLE选项的对话框时:
MyFragment fragment = new MyFragment();
fragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
fragment.show(getSupportFragmentManager(), "DIALOG");
Run Code Online (Sandbox Code Playgroud)
它会导致以下异常并崩溃:
05-19 12:18:38.806 15458-15458/? E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.example.test.testdialog, PID: 15458
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:302)
at android.app.Dialog.requestWindowFeature(Dialog.java:1066)
at android.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:317)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740) …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-dialogfragment android-support-library
所有流和bufferedReader都需要关闭我的问题是如果流和bufferedReader在一个方法内,参数/参数也需要关闭吗?
示例普通代码:
InputStream i = entity.getContent();
i.close();
Run Code Online (Sandbox Code Playgroud)
问:如果它在一个仅传递的方法的参数内部会怎么样?
public void doDownload(InputStream i, BufferedReader b) {
i.close();
b.close();
}
Run Code Online (Sandbox Code Playgroud)
即使输入流和bufferedreader只是一个参数而没有对象,我也应该关闭它吗?
我正在尝试缩放可绘制对象但失败了。然而,这不是本例中的问题,但它似乎与 setLevel() 方法有关。
我很难从文档中找出它的作用以及何时使用它:
指定可绘制对象的级别。这允许可绘制对象根据连续控制器改变其图像,例如显示进度或音量级别。
如果您提供的新关卡导致 Drawable 的外观发生变化,则它负责调用 invalidateSelf() 来重绘自身,并且该函数将返回 true。
参数 level 新级别,从 0(最小)到 10000(最大)。返回 如果级别的更改导致 Drawable 的外观发生变化(因此需要无效),则返回 true,否则返回 false。
例如控制器是什么?何时以及如何使用它?
在意图中我可以设置这样的标志FLAG_ACTIVITY_SINGLE_TOP.有人可以解释一下它的含义,因为我只是不明白吗?=)
所以我现在的问题是,现在我长时间点击ListView中的一个项目,它会调出一个上下文操作栏.传递给onItemLongClick的id是我想在mActionModeCallback的ActionItemClicked()方法中使用的变量.这似乎是一个相当常见的过程,因为如果用户正在编辑项目列表,您将希望在用户单击"编辑"或"删除"操作时以某种方式访问数据库中该行的ID.
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> p, View view, int pos, long id) {
//The id of the row in the database
long variableThatIWantToPassToCallback = id;
mActionMode = getActivity().startActionMode(mActionModeCallback);
view.setSelected(true);
return true;
}
});
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
public boolean onCreateActionMode(ActionMode mode, Menu menu) {}
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
//I would like access to the id of the clicked item here, NOT item.getItemId()
}
public void …Run Code Online (Sandbox Code Playgroud) 我想知道如何从特定日期的日历中获取活动我只想阅读所选日期的活动?
这样读取所有日历事件:
while (cur.moveToNext()) {
String title = null;
long eventID = 0;
long beginVal = 0;
// Get the field values
eventID = cur.getLong(PROJECTION_ID_INDEX);
beginVal = cur.getLong(PROJECTION_BEGIN_INDEX);
title = cur.getString(PROJECTION_TITLE_INDEX);
// Do something with the values.
Log.i(DEBUG_TAG, "Event: " + title);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(beginVal);
DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
Log.i(DEBUG_TAG, "Date: " + formatter.format(calendar.getTime()));
}
}
Run Code Online (Sandbox Code Playgroud)