Search in sources :

Example 1 with RequiresApi

use of androidx.annotation.RequiresApi in project kdeconnect-android by KDE.

the class ConnectivityReportPlugin method subscriptionsListen.

@RequiresApi(api = Build.VERSION_CODES.N)
private void subscriptionsListen() {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    subListener = TelephonyHelper.listenActiveSubscriptionIDs(context, subID -> {
        TelephonyManager subTm = tm.createForSubscriptionId(subID);
        Log.i("ConnectivityReport", "Added subscription ID " + subID);
        states.put(subID, new SubscriptionState(subID));
        PhoneStateListener listener = createListener(subID);
        listeners.put(subID, listener);
        subTm.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
    }, subID -> {
        Log.i("ConnectivityReport", "Removed subscription ID " + subID);
        tm.listen(listeners.get(subID), PhoneStateListener.LISTEN_NONE);
        listeners.remove(subID);
        states.remove(subID);
    });
}
Also used : RequiresApi(androidx.annotation.RequiresApi) Context(android.content.Context) PluginFactory(org.kde.kdeconnect.Plugins.PluginFactory) HashMap(java.util.HashMap) TelephonyHelper(org.kde.kdeconnect.Helpers.TelephonyHelper) R(org.kde.kdeconnect_tp.R) Objects(java.util.Objects) Manifest(android.Manifest) SignalStrength(android.telephony.SignalStrength) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Handler(android.os.Handler) PhoneStateListener(android.telephony.PhoneStateListener) TelephonyManager(android.telephony.TelephonyManager) OnSubscriptionsChangedListener(android.telephony.SubscriptionManager.OnSubscriptionsChangedListener) Build(android.os.Build) Plugin(org.kde.kdeconnect.Plugins.Plugin) NetworkPacket(org.kde.kdeconnect.NetworkPacket) Log(android.util.Log) SMSHelper(org.kde.kdeconnect.Helpers.SMSHelper) TelephonyManager(android.telephony.TelephonyManager) PhoneStateListener(android.telephony.PhoneStateListener) RequiresApi(androidx.annotation.RequiresApi)

Example 2 with RequiresApi

use of androidx.annotation.RequiresApi in project banner by youth5201314.

the class BannerUtils method setBannerRound.

/**
 * 设置view圆角
 *
 * @param radius
 * @return
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void setBannerRound(View view, float radius) {
    view.setOutlineProvider(new ViewOutlineProvider() {

        @Override
        public void getOutline(View view, Outline outline) {
            outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), radius);
        }
    });
    view.setClipToOutline(true);
}
Also used : Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) View(android.view.View) RequiresApi(androidx.annotation.RequiresApi)

Example 3 with RequiresApi

use of androidx.annotation.RequiresApi in project kdeconnect-android by KDE.

the class SmsMmsUtils method sendMmsMessageNative.

/**
 * Send an MMS message using SmsManager.sendMultimediaMessage
 *
 * @param context
 * @param message
 * @param klinkerSettings
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
protected static void sendMmsMessageNative(Context context, Message message, Settings klinkerSettings) {
    ArrayList<MMSPart> data = new ArrayList<>();
    for (Message.Part p : message.getParts()) {
        MMSPart part = new MMSPart();
        if (p.getName() != null) {
            part.Name = p.getName();
        } else {
            part.Name = p.getContentType().split("/")[0];
        }
        part.MimeType = p.getContentType();
        part.Data = p.getMedia();
        data.add(part);
    }
    if (message.getText() != null && !message.getText().equals("")) {
        // add text to the end of the part and send
        MMSPart part = new MMSPart();
        part.Name = "text";
        part.MimeType = "text/plain";
        part.Data = message.getText().getBytes();
        data.add(part);
    }
    SendReq sendReq = buildPdu(context, message.getFromAddress(), message.getAddresses(), message.getSubject(), data, klinkerSettings);
    Bundle configOverrides = new Bundle();
    configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, klinkerSettings.getGroup());
    // Write the PDUs to disk so that we can pass them to the SmsManager
    final String fileName = "send." + Math.abs(new Random().nextLong()) + ".dat";
    File mSendFile = new File(context.getCacheDir(), fileName);
    Uri contentUri = (new Uri.Builder()).authority(context.getPackageName() + ".MmsFileProvider").path(fileName).scheme(ContentResolver.SCHEME_CONTENT).build();
    try (FileOutputStream writer = new FileOutputStream(mSendFile)) {
        writer.write(new PduComposer(context, sendReq).make());
    } catch (final IOException e) {
        android.util.Log.e(SENDING_MESSAGE, "Error while writing temporary PDU file: ", e);
    }
    SmsManager mSmsManager;
    if (klinkerSettings.getSubscriptionId() < 0) {
        mSmsManager = SmsManager.getDefault();
    } else {
        mSmsManager = SmsManager.getSmsManagerForSubscriptionId(klinkerSettings.getSubscriptionId());
    }
    mSmsManager.sendMultimediaMessage(context, contentUri, null, null, null);
}
Also used : Message(com.klinker.android.send_message.Message) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SendReq(com.google.android.mms.pdu_alt.SendReq) Uri(android.net.Uri) PduComposer(com.google.android.mms.pdu_alt.PduComposer) SmsManager(android.telephony.SmsManager) Random(java.util.Random) FileOutputStream(java.io.FileOutputStream) MMSPart(com.google.android.mms.MMSPart) File(java.io.File) RequiresApi(androidx.annotation.RequiresApi)

Example 4 with RequiresApi

use of androidx.annotation.RequiresApi in project kdeconnect-android by KDE.

the class RunCommandActivity method onContextItemSelected.

@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    if (item.getItemId() == R.id.copy_url_to_clipboard) {
        CommandEntry entry = (CommandEntry) commandItems.get(info.position);
        String url = "kdeconnect://runcommand/" + deviceId + "/" + entry.getKey();
        ClipboardManager cm = ContextCompat.getSystemService(this, ClipboardManager.class);
        cm.setText(url);
        Toast toast = Toast.makeText(this, R.string.clipboard_toast, Toast.LENGTH_SHORT);
        toast.show();
        return true;
    }
    return false;
}
Also used : ClipboardManager(android.content.ClipboardManager) Toast(android.widget.Toast) AdapterView(android.widget.AdapterView) RequiresApi(androidx.annotation.RequiresApi)

Example 5 with RequiresApi

use of androidx.annotation.RequiresApi in project kdeconnect-android by KDE.

the class SendKeystrokesToHostActivity method onStart.

// needed for this.getReferrer()
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
@Override
protected void onStart() {
    super.onStart();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!prefs.getBoolean(getString(R.string.pref_sendkeystrokes_enabled), true)) {
        Toast.makeText(getApplicationContext(), R.string.sendkeystrokes_disabled_toast, Toast.LENGTH_LONG).show();
        finish();
    } else {
        final Intent intent = getIntent();
        String type = intent.getType();
        if ("text/x-keystrokes".equals(type)) {
            String toSend = intent.getStringExtra(Intent.EXTRA_TEXT);
            binding.textToSend.setText(toSend);
            // (contentIsOkay gets used in updateComputerList again)
            if (prefs.getBoolean(getString(R.string.pref_send_safe_text_immediately), true)) {
                SafeTextChecker safeTextChecker = new SafeTextChecker(SAFE_CHARS, MAX_SAFE_LENGTH);
                contentIsOkay = safeTextChecker.isSafe(toSend);
            } else {
                contentIsOkay = false;
            }
            // If we trust the sending app, check if there is only one device paired / reachable...
            if (contentIsOkay) {
                List<Device> reachableDevices = BackgroundService.getInstance().getDevices().values().stream().filter(Device::isReachable).limit(// we only need the first two; if its more than one, we need to show the user the device-selection
                2).collect(Collectors.toList());
                // if its exactly one just send the text to it
                if (reachableDevices.size() == 1) {
                    // send the text and close this activity
                    sendKeys(reachableDevices.get(0));
                    this.finish();
                    return;
                }
            }
            // subscribe to new connected devices
            BackgroundService.RunCommand(this, service -> {
                service.onNetworkChange();
                service.addDeviceListChangedCallback("SendKeystrokesToHostActivity", this::updateComputerList);
            });
            // list all currently connected devices
            updateComputerList();
        } else {
            Toast.makeText(getApplicationContext(), R.string.sendkeystrokes_wrong_data, Toast.LENGTH_LONG).show();
            finish();
        }
    }
}
Also used : SafeTextChecker(org.kde.kdeconnect.Helpers.SafeTextChecker) SharedPreferences(android.content.SharedPreferences) Device(org.kde.kdeconnect.Device) Intent(android.content.Intent) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

RequiresApi (androidx.annotation.RequiresApi)115 NotificationChannel (android.app.NotificationChannel)15 Intent (android.content.Intent)13 SuppressLint (android.annotation.SuppressLint)10 Uri (android.net.Uri)9 NonNull (androidx.annotation.NonNull)9 StatusBarNotification (android.service.notification.StatusBarNotification)8 IOException (java.io.IOException)8 NotificationManager (android.app.NotificationManager)7 PendingIntent (android.app.PendingIntent)6 Context (android.content.Context)6 ObjectAnimator (android.animation.ObjectAnimator)5 Notification (android.app.Notification)5 ByteBuffer (java.nio.ByteBuffer)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 SecretKey (javax.crypto.SecretKey)5 GestureDescription (android.accessibilityservice.GestureDescription)4 TaskStackBuilder (android.app.TaskStackBuilder)4 Bitmap (android.graphics.Bitmap)4 Rect (android.graphics.Rect)4