use of android.support.v4.app.NotificationCompat.Builder in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class Helpers method getOpenCellData.
public static void getOpenCellData(InjectionAppCompatActivity injectionActivity, Cell cell, char type, final AimsicdService service) {
if (Helpers.isNetAvailable(injectionActivity)) {
if (!"NA".equals(CellTracker.OCID_API_KEY)) {
// [Km]
double earthRadius = 6371.01;
// Use a 2 Km radius with center at GPS location.
int radius = 2;
if (Double.doubleToRawLongBits(cell.getLat()) != 0 && Double.doubleToRawLongBits(cell.getLon()) != 0) {
//New GeoLocation object to find bounding Coordinates
GeoLocation currentLoc = GeoLocation.fromDegrees(cell.getLat(), cell.getLon());
//Calculate the Bounding Box Coordinates using an N Km "radius" //0=min, 1=max
GeoLocation[] boundingCoords = currentLoc.boundingCoordinates(radius, earthRadius);
String boundParameter;
//Request OpenCellID data for Bounding Coordinates (0 = min, 1 = max)
boundParameter = String.valueOf(boundingCoords[0].getLatitudeInDegrees()) + "," + String.valueOf(boundingCoords[0].getLongitudeInDegrees()) + "," + String.valueOf(boundingCoords[1].getLatitudeInDegrees()) + "," + String.valueOf(boundingCoords[1].getLongitudeInDegrees());
log.info("OCID BBOX is set to: " + boundParameter + " with radius " + radius + " Km.");
StringBuilder sb = new StringBuilder();
sb.append("http://www.opencellid.org/cell/getInArea?key=").append(CellTracker.OCID_API_KEY).append("&BBOX=").append(boundParameter);
log.info("OCID MCC is set to: " + cell.getMobileCountryCode());
if (cell.getMobileCountryCode() != Integer.MAX_VALUE) {
sb.append("&mcc=").append(cell.getMobileCountryCode());
}
log.info("OCID MNC is set to: " + cell.getMobileNetworkCode());
if (cell.getMobileNetworkCode() != Integer.MAX_VALUE) {
sb.append("&mnc=").append(cell.getMobileNetworkCode());
}
sb.append("&format=csv");
new RequestTask(injectionActivity, type, new RequestTask.AsyncTaskCompleteListener() {
@Override
public void onAsyncTaskSucceeded() {
log.verbose("RequestTask's OCID download was successful. Callback rechecking connected cell against database");
service.getCellTracker().compareLacAndOpenDb();
}
@Override
public void onAsyncTaskFailed(String result) {
}
}).execute(sb.toString());
}
} else {
Fragment myFragment = injectionActivity.getSupportFragmentManager().findFragmentByTag(String.valueOf(DrawerMenu.ID.MAIN.ALL_CURRENT_CELL_DETAILS));
if (myFragment instanceof MapFragment) {
((MapFragment) myFragment).setRefreshActionButtonState(false);
}
Helpers.sendMsg(injectionActivity, injectionActivity.getString(R.string.no_opencellid_key_detected));
}
} else {
Fragment myFragment = injectionActivity.getSupportFragmentManager().findFragmentByTag(String.valueOf(DrawerMenu.ID.MAIN.ALL_CURRENT_CELL_DETAILS));
if (myFragment instanceof MapFragment) {
((MapFragment) myFragment).setRefreshActionButtonState(false);
}
final AlertDialog.Builder builder = new AlertDialog.Builder(injectionActivity);
builder.setTitle(R.string.no_network_connection_title).setMessage(R.string.no_network_connection_message);
builder.create().show();
}
}
use of android.support.v4.app.NotificationCompat.Builder in project Android-IMSI-Catcher-Detector by CellularPrivacy.
the class Helpers method importCellTowersData.
/**
* Description: Imports cell data from the specified file
*
* Used:
* @param celltowersPath path to the cell_towers.csv / cell_towers.csv.gz
* @param cell Current Cell Information
* @param importFile
*
*/
public static void importCellTowersData(InjectionAppCompatActivity injectionActivity, Cell cell, Uri importFile, final AimsicdService service) {
if (Helpers.isNetAvailable(injectionActivity)) {
// Use a 2 Km radius with center at GPS location.
int radius = 2;
if (Double.doubleToRawLongBits(cell.getLat()) != 0 && Double.doubleToRawLongBits(cell.getLon()) != 0) {
GeoLocation currentLoc = GeoLocation.fromDegrees(cell.getLat(), cell.getLon());
log.info("OCID location: " + currentLoc.toString() + " with radius " + radius + " Km.");
log.info("OCID MCC is set to: " + cell.getMobileCountryCode());
log.info("OCID MNC is set to: " + cell.getMobileNetworkCode());
new ImportTask(injectionActivity, importFile, cell.getMobileCountryCode(), cell.getMobileNetworkCode(), currentLoc, radius, new ImportTask.AsyncTaskCompleteListener() {
@Override
public void onAsyncTaskSucceeded() {
log.verbose("ImportTask's OCID import was successful. Callback rechecking connected cell against database");
service.getCellTracker().compareLacAndOpenDb();
}
@Override
public void onAsyncTaskFailed(String result) {
}
}).execute();
}
} else {
Fragment myFragment = injectionActivity.getSupportFragmentManager().findFragmentByTag(String.valueOf(DrawerMenu.ID.MAIN.ALL_CURRENT_CELL_DETAILS));
if (myFragment instanceof MapFragment) {
((MapFragment) myFragment).setRefreshActionButtonState(false);
}
final AlertDialog.Builder builder = new AlertDialog.Builder(injectionActivity);
builder.setTitle(R.string.no_network_connection_title).setMessage(R.string.no_network_connection_message);
builder.create().show();
}
}
use of android.support.v4.app.NotificationCompat.Builder in project AntennaPod by AntennaPod.
the class DownloadService method postAuthenticationNotification.
private void postAuthenticationNotification(final DownloadRequest downloadRequest) {
handler.post(() -> {
final String resourceTitle = (downloadRequest.getTitle() != null) ? downloadRequest.getTitle() : downloadRequest.getSource();
NotificationCompat.Builder builder = new NotificationCompat.Builder(DownloadService.this);
builder.setTicker(getText(R.string.authentication_notification_title)).setContentTitle(getText(R.string.authentication_notification_title)).setContentText(getText(R.string.authentication_notification_msg)).setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.authentication_notification_msg) + ": " + resourceTitle)).setSmallIcon(R.drawable.ic_stat_authentication).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_authentication)).setAutoCancel(true).setContentIntent(ClientConfig.downloadServiceCallbacks.getAuthentificationNotificationContentIntent(DownloadService.this, downloadRequest)).setVisibility(Notification.VISIBILITY_PUBLIC);
Notification n = builder.build();
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(downloadRequest.getSource().hashCode(), n);
});
}
use of android.support.v4.app.NotificationCompat.Builder in project acra by ACRA.
the class ReportExecutor method createNotification.
/**
* Creates a status bar notification.
*
* The action triggered when the notification is selected is to start the
* {@link CrashReportDialog} Activity.
*
* @param reportFile Report file to send.
*/
private void createNotification(@NonNull File reportFile, @NonNull ReportBuilder reportBuilder) {
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Default notification icon is the warning symbol
final int icon = config.resNotifIcon();
final CharSequence tickerText = context.getText(config.resNotifTickerText());
final long when = System.currentTimeMillis();
if (ACRA.DEV_LOGGING)
ACRA.log.d(LOG_TAG, "Creating Notification for " + reportFile);
final Intent crashReportDialogIntent = createCrashReportDialogIntent(reportFile, reportBuilder);
final PendingIntent contentIntent = PendingIntent.getActivity(context, mNotificationCounter++, crashReportDialogIntent, PendingIntent.FLAG_UPDATE_CURRENT);
final CharSequence contentTitle = context.getText(config.resNotifTitle());
final CharSequence contentText = context.getText(config.resNotifText());
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
final Notification notification = builder.setSmallIcon(icon).setTicker(tickerText).setWhen(when).setAutoCancel(true).setContentTitle(contentTitle).setContentText(contentText).setContentIntent(contentIntent).build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// The deleteIntent is invoked when the user swipes away the Notification.
// In this case we invoke the CrashReportDialog with EXTRA_FORCE_CANCEL==true
// which will cause BaseCrashReportDialog to clear the crash report and finish itself.
final Intent deleteIntent = createCrashReportDialogIntent(reportFile, reportBuilder);
deleteIntent.putExtra(ACRAConstants.EXTRA_FORCE_CANCEL, true);
notification.deleteIntent = PendingIntent.getActivity(context, -1, deleteIntent, 0);
// Send new notification
notificationManager.notify(ACRAConstants.NOTIF_CRASH_ID, notification);
}
use of android.support.v4.app.NotificationCompat.Builder in project AntennaPod by AntennaPod.
the class ProxyDialog method test.
private void test() {
if (subscription != null) {
subscription.unsubscribe();
}
if (!checkValidity()) {
setTestRequired(true);
return;
}
TypedArray res = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary });
int textColorPrimary = res.getColor(0, 0);
res.recycle();
String checking = context.getString(R.string.proxy_checking);
txtvMessage.setTextColor(textColorPrimary);
txtvMessage.setText("{fa-circle-o-notch spin} " + checking);
txtvMessage.setVisibility(View.VISIBLE);
subscription = Observable.create(new Observable.OnSubscribe<Response>() {
@Override
public void call(Subscriber<? super Response> subscriber) {
String type = (String) spType.getSelectedItem();
String host = etHost.getText().toString();
String port = etPort.getText().toString();
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
int portValue = 8080;
if (!TextUtils.isEmpty(port)) {
portValue = Integer.valueOf(port);
}
SocketAddress address = InetSocketAddress.createUnresolved(host, portValue);
Proxy.Type proxyType = Proxy.Type.valueOf(type.toUpperCase());
Proxy proxy = new Proxy(proxyType, address);
OkHttpClient.Builder builder = AntennapodHttpClient.newBuilder().connectTimeout(10, TimeUnit.SECONDS).proxy(proxy);
builder.interceptors().clear();
OkHttpClient client = builder.build();
if (!TextUtils.isEmpty(username)) {
String credentials = Credentials.basic(username, password);
client.interceptors().add(chain -> {
Request request = chain.request().newBuilder().header("Proxy-Authorization", credentials).build();
return chain.proceed(request);
});
}
Request request = new Request.Builder().url("http://www.google.com").head().build();
try {
Response response = client.newCall(request).execute();
subscriber.onNext(response);
} catch (IOException e) {
subscriber.onError(e);
}
subscriber.onCompleted();
}
}).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(response -> {
int colorId;
String icon;
String result;
if (response.isSuccessful()) {
colorId = R.color.download_success_green;
icon = "{fa-check}";
result = context.getString(R.string.proxy_test_successful);
} else {
colorId = R.color.download_failed_red;
icon = "{fa-close}";
result = context.getString(R.string.proxy_test_failed);
}
int color = ContextCompat.getColor(context, colorId);
txtvMessage.setTextColor(color);
String message = String.format("%s %s: %s", icon, result, response.message());
txtvMessage.setText(message);
setTestRequired(!response.isSuccessful());
}, error -> {
String icon = "{fa-close}";
String result = context.getString(R.string.proxy_test_failed);
int color = ContextCompat.getColor(context, R.color.download_failed_red);
txtvMessage.setTextColor(color);
String message = String.format("%s %s: %s", icon, result, error.getMessage());
txtvMessage.setText(message);
setTestRequired(true);
});
}
Aggregations