基于形意的so实现部分系统功能
parent
2899def777
commit
cd16668afd
Binary file not shown.
@ -0,0 +1,84 @@
|
|||||||
|
package com.xinyingpower.microphoto;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class FileDownloader {
|
||||||
|
protected void download(String urlString, String filePath) {
|
||||||
|
File downloadFile = null;
|
||||||
|
if (TextUtils.isEmpty(urlString))
|
||||||
|
return;
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
try {
|
||||||
|
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setReadTimeout(60000);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
InputStream is = connection.getInputStream();
|
||||||
|
final File temp = new File(filePath);
|
||||||
|
if (temp.exists())
|
||||||
|
temp.delete();
|
||||||
|
temp.createNewFile();
|
||||||
|
temp.setReadable(true, false);
|
||||||
|
temp.setWritable(true, false);
|
||||||
|
downloadFile = temp;
|
||||||
|
Log.d("download", "url " + urlString + "\n save to " + temp);
|
||||||
|
OutputStream os = new FileOutputStream(temp);
|
||||||
|
byte[] buf = new byte[8 * 1024];
|
||||||
|
int len;
|
||||||
|
try {
|
||||||
|
while ((len = is.read(buf)) != -1) {
|
||||||
|
os.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
os.flush();
|
||||||
|
if (os instanceof FileOutputStream) {
|
||||||
|
((FileOutputStream) os).getFD().sync();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
closeSilently(os);
|
||||||
|
closeSilently(is);
|
||||||
|
}
|
||||||
|
Log.d("downloadAPK", "download complete url=" + urlString + ", fileSize= " + temp.length());
|
||||||
|
// installPkg(this, temp, pkg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w("downloadAPK", e);
|
||||||
|
if (downloadFile != null)
|
||||||
|
downloadFile.delete();
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (connection != null)
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void closeSilently(Object closeable) {
|
||||||
|
try {
|
||||||
|
if (closeable != null) {
|
||||||
|
if (closeable instanceof Closeable) {
|
||||||
|
((Closeable) closeable).close();
|
||||||
|
} else if (closeable instanceof Socket) {
|
||||||
|
((Socket) closeable).close();
|
||||||
|
} else if (closeable instanceof ServerSocket) {
|
||||||
|
((ServerSocket) closeable).close();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Unknown object to close");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.xinyingpower.microphoto;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationListener;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
import android.location.LocationProvider;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public class PositionManager {
|
||||||
|
private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER;
|
||||||
|
private LocationManager mLocationManager;
|
||||||
|
private boolean mIsGpsEnabled;
|
||||||
|
private String mLocateType;
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
public PositionManager(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGpsEnabled() {
|
||||||
|
return mIsGpsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLocation() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue