android 11 part 3, split api 10/19
This commit is contained in:
parent
ae120c9f5a
commit
f6e014f61d
17 changed files with 446 additions and 93 deletions
|
|
@ -0,0 +1,27 @@
|
|||
package btools.routingapp;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.os.StatFs;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class BInstallerMainActivity extends Activity {
|
||||
|
||||
|
||||
static public long getAvailableSpace (String baseDir) {
|
||||
StatFs stat = new StatFs(baseDir);
|
||||
return (long)stat.getAvailableBlocks()*stat.getBlockSize();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
package btools.routingapp;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerManager.WakeLock;
|
||||
import android.os.StatFs;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import btools.router.OsmNodeNamed;
|
||||
|
||||
public class BRouterMainActivity extends Activity
|
||||
{
|
||||
|
||||
public boolean checkSelfPermission (Context context, String perm ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getStorageState(File f ) {
|
||||
return Environment.getExternalStorageState();
|
||||
}
|
||||
|
||||
public ArrayList<File> getStorageDirectories() {
|
||||
List<String> list = getFilesDirs();
|
||||
ArrayList<File> flist = new ArrayList<>();
|
||||
for (String s: list) {
|
||||
File f = new File(s);
|
||||
flist.add(f);
|
||||
}
|
||||
return flist;
|
||||
}
|
||||
|
||||
private List<String> getFilesDirs()
|
||||
{
|
||||
ArrayList<String> res = new ArrayList<String>();
|
||||
|
||||
// check write access on internal sd
|
||||
try
|
||||
{
|
||||
File sd = Environment.getExternalStorageDirectory();
|
||||
File testDir = new File( sd, "brouter" );
|
||||
boolean didExist = testDir.isDirectory();
|
||||
if ( !didExist )
|
||||
{
|
||||
testDir.mkdir();
|
||||
}
|
||||
File testFile = new File( testDir, "test" + System.currentTimeMillis() );
|
||||
testFile.createNewFile();
|
||||
if ( testFile.exists() )
|
||||
{
|
||||
testFile.delete();
|
||||
res.add( sd.getPath() );
|
||||
}
|
||||
if ( !didExist )
|
||||
{
|
||||
testDir.delete();
|
||||
}
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
|
||||
/*
|
||||
// not on api 10
|
||||
try
|
||||
{
|
||||
Method method = Context.class.getDeclaredMethod("getExternalFilesDirs", new Class[]{ String.class } );
|
||||
File[] paths = (File[])method.invoke( this, new Object[1] );
|
||||
for( File path : paths )
|
||||
{
|
||||
res.add( path.getPath() );
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
res.add( e.toString() );
|
||||
res.add( Environment.getExternalStorageDirectory().getPath() );
|
||||
}
|
||||
*/
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
package btools.routingapp;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioAttributes;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
|
||||
import static android.content.Context.NOTIFICATION_SERVICE;
|
||||
|
||||
public class NotificationHelper {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
public static String BRouterNotificationChannel1 = "brouter_channel_01";
|
||||
|
||||
private Context mContext;
|
||||
private int NOTIFICATION_ID = 111;
|
||||
private Notification mNotification;
|
||||
private NotificationManager mNotificationManager;
|
||||
private PendingIntent mContentIntent;
|
||||
private CharSequence mContentTitle;
|
||||
|
||||
public NotificationHelper(Context context)
|
||||
{
|
||||
if (DEBUG) Log.d("NH", "init " );
|
||||
mContext = context;
|
||||
createNotificationChannels();
|
||||
}
|
||||
|
||||
public void startNotification(Service service) {
|
||||
if (DEBUG) Log.d("NH", "startNotification " );
|
||||
|
||||
mNotification = createNotification("BRouter Download", "Download some files");
|
||||
if (mNotification != null) {
|
||||
NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
|
||||
}
|
||||
}
|
||||
|
||||
public void progressUpdate(String text) {
|
||||
mNotification = createNotification("BRouter Download", text);
|
||||
|
||||
if (mNotification != null) {
|
||||
mNotification.flags = Notification.FLAG_NO_CLEAR |
|
||||
Notification.FLAG_ONGOING_EVENT;
|
||||
NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Notification createNotification(String title, String desc) {
|
||||
|
||||
Intent resultIntent = new Intent(mContext, BInstallerActivity.class);
|
||||
|
||||
Intent notificationIntent = new Intent();
|
||||
mContentIntent = PendingIntent.getActivity(mContext, 0, resultIntent, PendingIntent.FLAG_IMMUTABLE);
|
||||
|
||||
Notification.Builder builder ;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
builder = new Notification.Builder(mContext);
|
||||
builder.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setContentTitle(title)
|
||||
.setContentText(desc)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setContentIntent(mContentIntent);
|
||||
|
||||
if(Build.VERSION.SDK_INT>=11 && Build.VERSION.SDK_INT<=15)
|
||||
return builder.getNotification();
|
||||
else if (Build.VERSION.SDK_INT > 15)
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* create notification channels
|
||||
*/
|
||||
public void createNotificationChannels() {
|
||||
if (DEBUG) Log.d("NH", "createNotificationChannels " );
|
||||
|
||||
}
|
||||
|
||||
public void stopNotification() {
|
||||
if (DEBUG) Log.d("NH", "stopNotification " );
|
||||
NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
mNotificationManager.deleteNotificationChannel(BRouterNotificationChannel1);
|
||||
}
|
||||
mNotificationManager.cancel(NOTIFICATION_ID);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue