Bitmap bmp = intent.getExtras().get("data");
int size = bmp.getRowBytes() * bmp.getHeight();
ByteBuffer b = ByteBuffer.allocate(size);
bmp.copyPixelsToBuffer(b);
byte[] bytes = new byte[size];
try {
b.get(bytes, 0, bytes.length);
} catch (BufferUnderflowException e) {
// always happens
}
// do something with byte[]
Run Code Online (Sandbox Code Playgroud)
当我在调用copyPixelsToBuffer
字节后查看缓冲区全部为0 ...从摄像机返回的位图是不可变的......但这应该无关紧要,因为它正在进行复制.
这段代码有什么问题?
好的,我有一个扩展SurfaceView和覆盖的类
surfaceChanged - 只需调用startPreview
surfaceCreated - 打开相机,编辑params*,设置surfaceHolder
surfaceDestroyed - 调用stopPreview,释放相机
这一切都很有效,因为当方向是肖像:
来自surfaceCreated*
m_camera = Camera.open();
Camera.Parameters p = m_camera.getParameters();
if (getResources().getConfiguration().orientation !=
Configuration.ORIENTATION_LANDSCAPE)
{
p.set("orientation", "portrait");
// CameraApi is a wrapper to check for backwards compatibility
if (CameraApi.isSetRotationSupported())
{
CameraApi.setRotation(p, 90);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,每次方向改变时,它都会调用Camera.open()......正如您所知,这是一项非常昂贵的操作,导致转换不是那么顺利.
当我强制定位到横向时,预览很棒.创建只调用一次,因为预览是横向的,相机始终是用户看到的.但是,我需要一种方法来设置纵向拍摄时实际拍摄的照片的方向.当我强制横向渲染时,表面永远不会被重新创建,并且当相机以纵向方式保持时,参数永远不会被设置.
那么如何才能完成以下任一项(专门)?
当方向发生变化时,保持 onDestroy和onCreate之间的m_camera,以便过渡平滑
强制风景和检测方向改变另一种方式...旋转最终的snaped图片,如果保持纵向.
此外,如果我离开基地,有人能指出我更好的方向吗?谢谢.
android smartphone orientation android-sdk-2.1 android-camera
真的不确定如何搜索这个......
每当在我的队列中添加或删除作业以在状态栏中发出通知时,我都会调用以下内容:
private void showNotification()
{
int jobsize = mJobQueue.size();
int icon = (jobsize == 0) ?
android.R.drawable.stat_sys_upload_done :
android.R.drawable.stat_sys_upload;
Notification notification =
new Notification(icon, "Test", System.currentTimeMillis());
Intent intent = new Intent(this, FileManagerActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.flags =
(Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL);
notification.setLatestEventInfo(this,
"Uploading to our servers",
getString((jobsize > 0) ?
R.string.notification_active_transfers :
R.string.notification_no_transfers),
pendingIntent);
mNotifyManager.notify(NOTIFICATION, notification);
}
Run Code Online (Sandbox Code Playgroud)
现在的行为是这样的:
如果用户注销并点击通知,它仍然会打开一个新的FileManagerActivity(操作!)我可以通过启动我的身份验证活动并以自然顺序将意图传递给我的堆栈来解决这个问题,当应用程序已经是跑步是我遇到困难的地方.
如果用户已经打开FileManagerActivity,则单击该通知将在其上放置第二个实例.在这种情况下,我希望当前运行的FileManagerActivity接收焦点而不是启动新实例.
我怎么能得到正确的行为?
notifications android android-activity android-pendingintent
// Application ...
Intent i = new Intent();
i.putExtra(EXTRA_FILE_UPLOAD_URIS, mGalleryAdapter.getItems());
Uri[] getItems() { return mItems; }
// Service ...
intent.getParcelableArrayExtra(EXTRA_FILE_UPLOAD_URIS); //works, returns Parcelable[]
Uri[] uris = (Uri[])intent.getParcelableArrayExtra(EXTRA_FILE_UPLOAD_URIS);
// ... Breaks with ClassCastException
Run Code Online (Sandbox Code Playgroud)
为什么投给Uri[]
打破,当Uri
是Parcelable
?
首先,对不起,如果有人问我但找不到它.我正在从远程资源下载我的应用程序中的文档.下载文档后,我想为用户打开它.我想知道的是我如何检查他们是否有应用程序来处理Pdf或Tiff并在默认应用程序中启动它?
谢谢.
编辑
这是解决方案的一部分:
Intent viewDoc = new Intent(Intent.ACTION_VIEW);
viewDoc.setDataAndType(
Uri.fromFile(getFileStreamPath("test.pdf")),
"application/pdf");
PackageManager pm = getPackageManager();
List<ResolveInfo> apps =
pm.queryIntentActivities(viewDoc, PackageManager.MATCH_DEFAULT_ONLY);
if (apps.size() > 0)
startActivity(viewDoc);
Run Code Online (Sandbox Code Playgroud) 如果日期介于某个范围之间,我可以找到如何获取,但我似乎无法在特定时间创建日期.
什么是最简单的方法来查看[NSDate日期]是否在一个时间范围之间?
我想显示如下的个性化问候语:
下午12点 - 4:59:9999 @"下午好,foo"下午
5点 - 晚上9点59分:晚上9点9分"晚上好,foo"
12点 - 11:59:9999上午@"早上好,foo"
我有一个我在一些.h文件中声明的枚举:
typedef enum {
NONE,
ONE,
TWO,
THREE
} MYENUM;
Run Code Online (Sandbox Code Playgroud)
在一个单独的.cpp我不能这样做:
extern enum MYENUM; //works
extern MYENUM TWO; //makes sence, TWO is not an INSTANCE of MYENUM...
Run Code Online (Sandbox Code Playgroud)
怎么会这样做而不包括枚举枚举的整个标题?
正如标题所说,我的UncaughtExceptionHandler
自定义应用程序类中有一个集合,在我的应用程序启动时被设置为默认值.
但是,虽然没有在文档中我读过你无法实例化Dialog
使用MyApplication.this
或getApplicationContext()
.当我尝试这样做时,我会得到一个
窗口管理器,$ BadTokenException ...
我需要另一种选择.我曾想过要做一个新的活动来弥补这一点,但宁愿让它成为一个AlertDialog
.
有没有办法可以UncaughtExceptionHandler
从MyApplication
课堂内获得有效的上下文?
我在AppStore上发布了一个应用程序,我希望将其迁移到企业开发人员帐户以进行内部分发.我在企业文档中读到:
如果您希望用户将应用程序的数据保存在其设备上,请确保新版本使用与其替换的相同的捆绑标识符,并告知用户在安装新版本之前不要删除旧版本.如果bundle-identifiers匹配,则新版本将替换旧版本并将数据保存在设备上.
现在,假设我们保持已安装的AppStore二进制文件与使用不同证书签名的企业二进制文件之间的Bundle ID相同......它应该覆盖手机上的相同应用程序,而不是创建第二个应用程序.
我联系了Apple支持,他们说:"不,如果你没有指示客户卸载他们的旧应用程序,你将安装2个应用程序".这是真的?
显然,Visual Studio 2010构建的DLL不支持Windows 2000.有没有办法构建Windows 2000支持?
如果没有,我想将我的解决方案转换为在Visual Studio 2008中编译.我将解决方案降级,但项目文件似乎很棘手.我相信他们已经在版本之间改变了相当多的格式.我将如何降级项目文件?
visual-studio-2010 visual-studio-2008 visual-c++ windows-2000
android ×6
ios ×2
iphone ×2
java ×2
bitmap ×1
bytebuffer ×1
c++ ×1
compilation ×1
document ×1
exception ×1
extern ×1
file-io ×1
filehandler ×1
linkage ×1
nsdate ×1
objective-c ×1
orientation ×1
parcelable ×1
smartphone ×1
syntax ×1
visual-c++ ×1
windows-2000 ×1