在我的应用程序中我从webserver下载kml文件.我已经在我的android清单文件中设置了外部存储和互联网的权限.我是android的新手,非常感谢你的帮助
MainActivity.java
package com.example.demo;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DownloadFiles();
}
public void DownloadFiles(){
try {
URL u = new URL("http://www.qwikisoft.com/demo/ashade/20001.kml");
InputStream is = u.openStream();
DataInputStream dis = new DataInputStream(is);
byte[] buffer = new byte[1024];
int length;
FileOutputStream fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory() + "/" + "data/test.kml")); …
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中我使用phonegap 2.6.对于后退按钮,我使用以下功能
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
alert("hello");
navigator.app.backHistory();
}
document.addEventListener('deviceready', onDeviceReady, true);
Run Code Online (Sandbox Code Playgroud)
单击设备的硬件后退按钮时,上述功能正常.但是,当我点击后退按钮时,它无法正常工作.
我设计了我的后退按钮如下:
<a class="ui-link" href="#" rel="external" onclick="onBackKeyDown()">
<img src="images/icon-back.png" alt="Phone" border="0">
</a>
Run Code Online (Sandbox Code Playgroud)
但是这个按钮工作正常navigator.app.exitApp();
(应用程序退出).
//Working Fine
function onBackKeyDown() {
navigator.app.exitApp();
}
//Not Working
function onBackKeyDown() {
navigator.app.backHistory();
}
Run Code Online (Sandbox Code Playgroud)
但不是为了工作navigator.app.backHistory();
.
我正在为Android/IOS做推送.我使用了一个phonegap push-plugin https://github.com/phonegap-build/PushPlugin,它看起来效果很好.
我现在在我的设备上收到消息问题是当我点击收到的消息时它会转到app index.html page.But我想打开另一个页面,例如home.html当我点击消息并在home.html我会正在显示消息.
怎么做到这一点?
MyPhoneGapActivity.java
package com.test;
import org.apache.cordova.DroidGap;
import android.os.Bundle;
public class MyPhoneGapActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html", 10000);
}
}
Run Code Online (Sandbox Code Playgroud)
index.js
<script type="text/javascript">
var pushNotification;
function onDeviceReady() {
$("#app-status-ul").append('<li>deviceready event received</li>');
document.addEventListener("backbutton", function(e)
{
$("#app-status-ul").append('<li>backbutton event received</li>');
if( $("#home").length > 0)
{
// call this to get a new token each time. don't call it to reuse existing token.
//pushNotification.unregister(successHandler, errorHandler);
e.preventDefault();
navigator.app.exitApp();
} …
Run Code Online (Sandbox Code Playgroud)