我正在研究简单的应用程序,以显示不同形式的时间.显示使用此ISO代码显示ISO国家/地区代码的时间.我能否以ISO国家/地区格式更改时间?
我编写的代码如下
TelephonyManager tMgr =
(TelephonyManager)getApplicationContext().getSystemService(
Context.TELEPHONY_SERVICE);
String iso = tMgr.getNetworkCountryIso();
Log.v("Device iso", "=======>" + iso);
String mbNo = tMgr.getLine1Number();
Log.v("mbNo", "=======>" + mbNo);
Run Code Online (Sandbox Code Playgroud)
我在这里获得iso作为美国.我可以用美国时间格式显示当前的系统时间格式吗?
我使用Date类来显示时间如下
DateFormat df = DateFormat.getTimeInstance();
systime = df.format(new Date());
Run Code Online (Sandbox Code Playgroud)
它以HH:MM:SS AM/PM格式显示时间.我想将上述时间显示为美国格式.
如何以美国或任何其他格式显示时间?
我想从我的Android设备获取所有图像/照片/壁纸与图像保存路径.
我已经实现了从sdcard收集图像的代码,如下所示:
String[] mProjection = {
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA
};
mCursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
mProjection,
null,
null,
MediaStore.Images.Media.DEFAULT_SORT_ORDER);
Run Code Online (Sandbox Code Playgroud)
从上面的代码我只能从sdcard中检索图像.但如果图像在设备手机内存中可用,那么我该如何检索图像/照片/壁纸?如果我使用INTERNAL_CONTENT_URI它不会返回wallapers info其他图像信息
请任何身体帮助我....
我的应用程序中有一个异步下载器,但有时连接丢失,特别是当我在移动连接上并且文件很大(> 10 MB)时.有没有办法在下载停止时捕获,然后强制它继续完成下载的结果?
这是异步任务doInBackground:
protected String doInBackground(String... aurl) {
int count;
try {
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
// conexion.setRequestProperty("Range", "bytes=" + downloaded + "-");
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
pesoVideo = lenghtOfFile / 1048576;
output = "/sdcard/" + folderString + "/" + nomeFile + ".mp3";
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(
VideoDownloaderBrowserActivity.this.output);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total …Run Code Online (Sandbox Code Playgroud) 如果有人知道如何将远程文件直接流式传输到文件对象的快速方法,那么没有必要将文件临时存储在计算机上,我们将不胜感激!到目前为止,我从远程ios设备复制文件如下(使用net.schmizz.sshj):
SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(fingerprint);
ssh.connect(ip);
try {
ssh.authPassword("username", "userpassword".toCharArray());
ssh.newSCPFileTransfer().download(fileRemote, new FileSystemFile(fileLocal));
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
ssh.disconnect();
}
Run Code Online (Sandbox Code Playgroud)
如果有人对解决方案的代码感兴趣:
正如Nutlike在回答中提到的那样,最好使用它InMemoryDestFile.所以创建以下类:
class MyInMemoryDestFile extends InMemoryDestFile {
public ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@Override
public ByteArrayOutputStream getOutputStream() throws IOException {
return this.outputStream;
}
}
Run Code Online (Sandbox Code Playgroud)
...在执行下载操作的方法中,创建新类的实例:
MyInMemoryDestFile a = new StreamingInMemoryDestFile();
Run Code Online (Sandbox Code Playgroud)
并访问输出流:
ssh.newSCPFileTransfer().download(remoteFile, a);
a.getOutputStream().toByteArray();
Run Code Online (Sandbox Code Playgroud)
最好的祝福
我正在尝试测试以下JavaScript代码,这是为了跟踪用户对多项选择调查的响应时间:
document.onclick = function(e) {
var event = e || window.event;
var target = e.target || e.srcElement;
//time tracking
var ClickTrackDate = new Date;
var ClickData = "";
ClickData = target.id + "=" + ClickTrackDate.getUTCHours() + ":" +
ClickTrackDate.getUTCMinutes() + ":" +
ClickTrackDate.getUTCSeconds() +";";
document.getElementById("txtTest").value += ClickData;
alert(target.id); // for testing
}
Run Code Online (Sandbox Code Playgroud)
通常target.id等于被点击元素的id,正如您所期望的那样,但有时target.id是空的,看似随意,任何想法?
如果有人可以向我解释为什么u = bar(u,r)在以下代码中无效,我会非常感激.我找不到正确的解释.
class R {
}
class U {
}
public class Foo {
public static <T> T bar(T x, T y) {
return x;
}
public static void main(String[] args) {
R r = new R();
U u = new U();
u = bar(u,r); // why is this not working?
}
}
Run Code Online (Sandbox Code Playgroud)
更新:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from Object to U
Run Code Online (Sandbox Code Playgroud) 我正在学习使用泛型类型的java编程,并得到一个可能非常基本的问题.
另外两个片段之间的区别在哪里?
1.)
public void build(House house) {
// work only with house objects that extending House
}
Run Code Online (Sandbox Code Playgroud)
2.)
public <T extends House> void build(T house) {
// work only with house objects that extending House
}
Run Code Online (Sandbox Code Playgroud) //About Button in the principal menu
final Button button3 = (Button) findViewById(R.id.button3);
button3.setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
//set up dialog
Dialog dialog = new Dialog(MainMenu.this);
dialog.setContentView(R.layout.maindialog);
dialog.setTitle("About");
dialog.setCancelable(true);
//now that the dialog is set up, it's time to show it
dialog.show();
Button closeButton = (Button) dialog.findViewById(R.id.Button01);
// closeButton.setOnClickListener(new Button.OnClickListener() {
// public void onClick(View view) {
// dialog.dismiss();
// }
// });
if(v==closeButton)
dialog.dismiss();
}
});
Run Code Online (Sandbox Code Playgroud)
我有这个代码,但解雇不起作用.
我有一个"约"按钮,当我点击它时会显示对话框窗口.然后对话框窗口有一个"确定"按钮,这个OK按钮应该关闭对话框但是解雇不起作用.你能帮我理解为什么吗?
import java.io.*;
import com.lowagie.text.DocumentException;
import org.xhtmlrenderer.pdf.ITextRenderer;
public class FirstDoc {
public static void main(String[] args)
throws IOException, DocumentException {
String url= "http://www.facebook.com";
String outputFile = "firstdoc.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误
> ERROR: 'Premature end of file.'
Exception in thread "main" org.xhtmlrenderer.util.XRRuntimeException: Can't load the XML resource (using TRaX transformer). org.xml.sax.SAXParseException: Premature end of file.
at org.xhtmlrenderer.resource.XMLResource$XMLResourceBuilder.createXMLResource(XMLResource.java:191)
at org.xhtmlrenderer.resource.XMLResource.load(XMLResource.java:71)
at org.xhtmlrenderer.swing.NaiveUserAgent.getXMLResource(NaiveUserAgent.java:205)
at org.xhtmlrenderer.pdf.ITextRenderer.loadDocument(ITextRenderer.java:102)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:106)
at com.test.java.FirstDoc.main(FirstDoc.java:17)
Caused …Run Code Online (Sandbox Code Playgroud) 我在Android上使用SQLite,在运行此命令时出现问题:
UPDATE vocab_words SET correct = 5
WHERE
name = 'AQA GCSE Spanish Higher',
foreign_word = 'campo, el',
english_meaning = 'field, the'
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?提前致谢.
当我使用带有比较器的Arrays.sort()和作为集合的列表(之前转换为数组)时,我得到一个类强制转换异常.这是我的代码:
List<SomeClazz> somes = new ArrayList<SomeClazz>();
Comparator<SomeClazz> attrComparator = new AttrComparator();
somes = createSomeObjectes(); // returnes a list of course
// this is line 25 where the exception occours
Arrays.sort((SomeClazz[])somes.toArray(), attrComparator);
Run Code Online (Sandbox Code Playgroud)
例外消息:
Exception in thread "main" java.lang.ClassCastException:
[Ljava.lang.Object; cannot be
cast to [Lpack.SomeClazz; at pack.TestMain.main(TestMain.java:25)
Run Code Online (Sandbox Code Playgroud)
这可能是什么原因?提前thx!