广播

1.什么是广播        

2.标准广播

BroadStandardActivity.java

package com.tiger.chapter09;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import com.tiger.chapter09.receiver.StandardReceiver;

public class BroadStandardActivity extends AppCompatActivity implements View.OnClickListener {

    private StandardReceiver standardReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broad_standard);
        findViewById(R.id.btn_send_standard).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        //发送标准广播  相当于主题
        Intent intent = new Intent(StandardReceiver.STRING);



        sendBroadcast(intent);
    }


    @Override
    protected void onStart() {
        super.onStart();
        standardReceiver = new StandardReceiver();
        //代表上下文 注册 广播接收者  相当于订阅
        IntentFilter intentFilter = new IntentFilter(StandardReceiver.STRING);
        //注册接收器,注册之后才能正常接收广播
        registerReceiver(standardReceiver,intentFilter);
    }

    @Override
    protected void onStop() {
        super.onStop();
        //在Activity不用的时候就不需要 广播订阅了,先注销接收者
        unregisterReceiver(standardReceiver);


    }
}

xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp">

    <Button
        android:id="@+id/btn_send_standard"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="发送标准广播"
        android:textColor="@color/black"
        android:textSize="17sp" />

</LinearLayout>

receiver

package com.tiger.chapter09.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

//定义一个标准广播的接收器
public class StandardReceiver extends BroadcastReceiver {

    public static final String STRING ="com.tiger.chapter09.standard";
    //一旦接收到标准广播,马上触发接收器的onReceive方法
    @Override
    public void onReceive(Context context, Intent intent) {
        //先当于订阅主题
        if (intent!=null&&intent.getAction().equals(STRING)){
            Log.d("ning","收到了标准广播");
        }
    }
}

3.有序广播

 BroadOrderActivity.java

package com.tiger.chapter09;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import com.tiger.chapter09.receiver.OrderAReceiver;
import com.tiger.chapter09.receiver.OrderBReceiver;

public class BroadOrderActivity extends AppCompatActivity implements View.OnClickListener {

    public static final String ORDER_ACTION = "com.tiger.chapter09.order";
    private OrderAReceiver orderAReceiver;
    private OrderBReceiver orderBReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broad_order);
        findViewById(R.id.btn_send_order).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        //创建一个指定动作的意图
        Intent intent  =new Intent(ORDER_ACTION);
        //发送有序广播
        sendOrderedBroadcast(intent,null);
    }

    @Override
    protected void onStart() {
        super.onStart();
        //多个接收器处理有序广播的顺序规则为:
        //1.优先级越大的2接收器,越早收到有序广播
        //2.优先级相同的时候,越早注册的接收器越早收到有序广播
        orderAReceiver = new OrderAReceiver();
        IntentFilter filterA = new IntentFilter(ORDER_ACTION);
        filterA.setPriority(8);
        registerReceiver(orderAReceiver,filterA);

        orderBReceiver = new OrderBReceiver();
        IntentFilter filterB = new IntentFilter(ORDER_ACTION);
        filterB.setPriority(10);
        registerReceiver(orderBReceiver,filterB);


    }

    @Override
    protected void onStop() {
        super.onStop();
        unregisterReceiver(orderAReceiver);
        unregisterReceiver(orderBReceiver);
    }
}

AOrder

package com.tiger.chapter09.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.tiger.chapter09.BroadOrderActivity;

public class OrderAReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent!=null&&intent.getAction().equals(BroadOrderActivity.ORDER_ACTION)){
            Log.d("ning","接收器A 收到了有序广播");
        }


    }
}

BOrder

package com.tiger.chapter09.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.tiger.chapter09.BroadOrderActivity;

public class OrderBReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent!=null&&intent.getAction().equals(BroadOrderActivity.ORDER_ACTION)){
            Log.d("ning","接收器B 收到了有序广播");
            abortBroadcast();//中断广播,此时后面的接收器无法收到该广播
        }


    }
}

4.广播的静态注册

activity

package com.tiger.chapter09;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.tiger.chapter09.receiver.ShockReceiver;

public class BroadStaticActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broad_static);
        findViewById(R.id.btn_send_shock).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        //Android8.0 之后 删除了大部分静态注册,防止退出App后仍在接收广播
        //为了让应用能够继续接收静态广播,需要给静态注册的广播指定包名

        String fullName = "com.tiger.chapter09.receiver.ShockReceiver";
        Intent intent = new Intent(ShockReceiver.SHOCK_ACTION);

        ComponentName componentName = new ComponentName(this, fullName);

        intent.setComponent(componentName);

        sendBroadcast(intent);

    }
}

 ShockReceiver

package com.tiger.chapter09.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.util.Log;

public class ShockReceiver extends BroadcastReceiver {

    public static final String SHOCK_ACTION="com.jmj.shock";
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent!=null&&intent.getAction().equals(SHOCK_ACTION)){
            Log.d("ning","震动一下");
            //从系统服务中获取震动管理器
            Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
            //震动需要权限,开启清单权限就不会报错了
                vb.vibrate(VibrationEffect.createOneShot(500,50));
        }

    }
}

清单文件 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!--    震动需要系统权限 -->
    <uses-permission android:name="android.permission.VIBRATE"/>
    
    
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">
        <receiver
            android:name=".receiver.ShockReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.jmj.shock"/>
            </intent-filter>

        </receiver>


        <activity
            android:name=".BroadStaticActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

5.系统分钟到达广播

Activity

package com.tiger.chapter09;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public class SystemMinuteActivity extends AppCompatActivity {

    private TimeReceiver timeReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_minute);
    }


    @Override
    protected void onStart() {
        super.onStart();
        //创建一个分钟变更的广播接收器
        timeReceiver = new TimeReceiver();
        IntentFilter filter = new IntentFilter(Intent.ACTION_TIME_TICK);
        registerReceiver(timeReceiver,filter);

    }

    @Override
    protected void onStop() {
        super.onStop();
        unregisterReceiver(timeReceiver);
    }
}

TimeReceiver

package com.tiger.chapter09;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class TimeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent!=null){
            Log.d("ning","收到一个分钟到达广播");
        }
    }
}

6.系统网络变更广播

SystemNetWorkActivity

package com.tiger.chapter09;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

import com.tiger.chapter09.receiver.NetWorkReceiver;

public class SystemNetWorkActivity extends AppCompatActivity {

    private NetWorkReceiver netWorkReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_system_net_work);
    }


    @Override
    protected void onStart() {
        super.onStart();
        netWorkReceiver = new NetWorkReceiver();
        IntentFilter filter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
        registerReceiver(netWorkReceiver,filter);

    }

    @Override
    protected void onStop() {
        super.onStop();
        unregisterReceiver(netWorkReceiver);

    }
}

NetWorkReceiver

package com.tiger.chapter09.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.os.Parcelable;
import android.util.Log;

import com.tiger.chapter09.util.NetworkUtil;

public class NetWorkReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            NetworkInfo networkInfo = intent.getParcelableExtra("networkInfo");
            // 收到一个网络变更广播,网络大类为MOBILE,网络小类为HSPA,网络制式为3G,网络状态为DISCONNECTED
            // 收到一个网络变更广播,网络大类为WIFI,网络小类为,网络制式为未知,网络状态为CONNECTED
            String text = String.format("收到一个网络变更广播,网络大类为%s," +
                            "网络小类为%s,网络制式为%s,网络状态为%s",
                    networkInfo.getTypeName(),
                    networkInfo.getSubtypeName(),
                    NetworkUtil.getNetworkClass(networkInfo.getSubtype()),
                    networkInfo.getState().toString());

            Log.d("ning", text);

        }

    }
}

NetWorkUtil

package com.tiger.chapter09.util;

import android.telephony.TelephonyManager;

public class NetworkUtil {
    // 获取数据连接的制式类型
    public static String getNetworkClass(int subType) {
        switch (subType) {
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_1xRTT:
            case TelephonyManager.NETWORK_TYPE_IDEN:
                return "2G";
            case TelephonyManager.NETWORK_TYPE_UMTS:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
            case TelephonyManager.NETWORK_TYPE_EHRPD:
            case TelephonyManager.NETWORK_TYPE_HSPAP:
                return "3G";
            case TelephonyManager.NETWORK_TYPE_LTE:
                return "4G";
            case TelephonyManager.NETWORK_TYPE_NR:
                return "5G";
            default:
                return "未知";
        }
    }
}

 

7. alarm定时器广播

package com.tiger.chapter09.receiver;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.util.Log;

public class AlarmReceiver extends BroadcastReceiver {

    public static final String ALARM_ACTION="com.tiger.chapter09.alarm";
    private Context mContext;

    public AlarmReceiver(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null&&intent.getAction().equals(ALARM_ACTION)){
            Log.d("ning","收到闹钟广播");
            sendAlarm();
        }
    }


    //发送闹钟广播的方法
    public void sendAlarm(){
        Intent intent = new Intent(ALARM_ACTION);
        // 创建一个用于广播的延迟意图
        // 针对 S+(版本 10000 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。
        // 强烈考虑使用 FLAG_IMMUTABLE,仅当某些功能依赖于 PendingIntent 是可变的时才使用 FLAG_MUTABLE
        PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_IMMUTABLE);
        // 从系统服务中获取闹钟管理器
        AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            // 允许在空闲时发送广播,Android6.0之后新增的方法
            alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, 1000, pendingIntent);
        }else{
            // 设置一次性闹钟,延迟若干秒后,携带延迟意图发送闹钟广播(但Android6.0之后,set方法在暗屏时不保证发送广播,
            // 必须调用setAndAllowWhileIdle方法)
            alarmManager.set(AlarmManager.RTC_WAKEUP, 1000, pendingIntent);
        }


        // 设置重复闹钟,每隔一定间隔就发送闹钟广播(但从Android4.4开始,setRepeating方法不保证按时发送广播)
//        alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
//                1000, pIntent);


    }
}
package com.tiger.chapter09;

import androidx.appcompat.app.AppCompatActivity;

import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import com.tiger.chapter09.receiver.AlarmReceiver;

public class AlarmActivity extends AppCompatActivity implements View.OnClickListener {

    private AlarmReceiver alarmReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm);
        findViewById(R.id.btn_alarm).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        alarmReceiver.sendAlarm();
    }


    @Override
    protected void onStart() {
        super.onStart();
        alarmReceiver = new AlarmReceiver(getApplicationContext());
        IntentFilter filter = new IntentFilter(AlarmReceiver.ALARM_ACTION);
        registerReceiver(alarmReceiver,filter);

    }

    @Override
    protected void onStop() {
        super.onStop();
        unregisterReceiver(alarmReceiver);
    }
}

8.竖屏与横屏切换

 

package com.tiger.chapter09;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class ChangeDirectionActivity extends AppCompatActivity {

    private TextView tv_monitor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_direction);
        tv_monitor = findViewById(R.id.tv_monitor);
        Log.d("ning","onCreate");//只执行一次,在屏幕旋转之后
    }

    //在配置项变更是触发。比如屏幕方向发生变更等等
    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        switch (newConfig.orientation){
            case Configuration.ORIENTATION_PORTRAIT:
                tv_monitor.setText("当前屏幕为竖屏方向");
                break;
            case Configuration.ORIENTATION_LANDSCAPE:
                tv_monitor.setText("当前屏幕为横屏方向");
                break;
            default:
                break;
        }

    }
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 震动需要系统权限 -->
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">


        <receiver
            android:name=".receiver.ShockReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.jmj.shock" />
            </intent-filter>
        </receiver>

        <activity
            android:name=".ChangeDirectionActivity"
            android:exported="true"
            android:configChanges="orientation|screenLayout|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

设置只能竖屏或者横屏

 <activity
            android:name=".ChangeDirectionActivity"
            android:exported="true"
            android:configChanges="orientation|screenLayout|screenSize"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

screenOrientation = portrait | landscape

9.回到桌面和使用任务列表

 
package com.tiger.chapter09;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.PictureInPictureParams;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.util.Rational;

public class ReturnDesktopActivity extends AppCompatActivity {

    private DesktopReceiver desktopReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_return_desktop);
    //因为按了Home或任务键 所以要在onCreate 和 Destroy 来注册 广播 要不然,stop就监听不到了
        desktopReceiver = new DesktopReceiver();
        IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        registerReceiver(desktopReceiver,filter);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(desktopReceiver);
    }

    //在进入画中画模式或退出画中画模式时触发
    @Override
    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, @NonNull Configuration newConfig) {
        super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
        if (isInPictureInPictureMode){
            //进入了画中画模式
            Log.d("ning","进入了画中画模式");
        }else {
            //退出了画中画模式
            Log.d("ning","退出了画中画模式");
        }

    }

    //定义一个返回到桌面的广播接收器
    private class DesktopReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent != null && intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
                //回到桌面或者切换到任务列表的主题广播
                String reason = intent.getStringExtra("reason");
                if (!TextUtils.isEmpty(reason)
                        && (reason.equals("homekey") || reason.equals("recentapps"))) {
                    //Android 8.0 开始才提供画中画模式

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !isInPictureInPictureMode()) {
                        //进入画中画模式 创建画中画模式的参数构造器
                        PictureInPictureParams.Builder builder = new PictureInPictureParams.Builder();
                        //设置宽高比例值,第一个参数表示分子,第二个参数表示分母
                        // 下面的10/5 =2,表示画中画窗口的宽度是高度的两倍
                        Rational rational = new Rational(10, 5);//宽 高 10 : 5
                        builder.setAspectRatio(rational);
                        //进入画中画模式
                        enterPictureInPictureMode(builder.build());
                    }
                }
            }
        }
    }


}

清单文件 开启画中画支持

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 震动需要系统权限 -->
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyApplication">


        <receiver
            android:name=".receiver.ShockReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.jmj.shock" />
            </intent-filter>
        </receiver>

        <activity
            android:name=".ReturnDesktopActivity"
            android:configChanges="orientation|screenLayout|screenSize"
            android:exported="true"
            android:screenOrientation="portrait"
            android:supportsPictureInPicture="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/439566.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

OPC UA 学习:文件传输

本博文是OPC 10000-20: UA Part 20: File Transfer 的学习笔记。 客户端需要读写服务器端的文件&#xff0c;OPCUA 规范中&#xff0c;是通过文件模型实现的。客户端通过调用文件模型中的方法来处理文件。 文件类型 文件类型&#xff08;FileType&#xff09;的属性 属性 文…

什么是工业物联网关?工业物联网关有什么作用?

在数字化和智能化浪潮席卷全球的今天&#xff0c;工业物联网&#xff08;IIoT&#xff09;成为了推动工业4.0革命的核心力量。而在这场革命中&#xff0c;工业物联网关发挥着至关重要的作用。那么&#xff0c;什么是工业物联网关&#xff1f;它又有哪些功能呢&#xff1f;今天&…

教育照明灯具十大排名榜有哪些?护眼台灯选购看这一篇就够了!

现在关于孩子的教育问题&#xff0c;父母还是十分重视的&#xff0c;当然除了让孩子接受良好的教育&#xff0c;给孩子营造良好的学习空间也成为了很多父母心中重要的事情&#xff0c;其中关于光线的问题不少&#xff0c;不良光线是很多孩子近视的导火索&#xff0c;而护眼台灯…

6、string字符串拼接

#include <iostream> using namespace std;void test01 () {string s1 "我";s1 "爱玩游戏";cout << s1 << endl;s1 :;string s2 "lol dnf";s1 s2;cout << s1 << endl;string s3 "i";s3.append(&q…

Docker容器的操作

目录 运行容器 查看容器 查看容器详细信息 删除容器 启动容器 停止容器 重启容器 暂停容器 激活容器 杀死容器 进入容器 常用 查看容器的日志 拷贝容器的文件到本地 容器改名 查看容器资源 查看容器内部的进程 监测容器发生的事件 检测容器停止以后的反回值…

【重要公告】BSV区块链协会开始对Teranode节点软件进行技术测试

​​发表时间&#xff1a;2024年2月22日 Teranode节点软件将使BSV区块链网络的交易处理速度提升至每秒110万笔&#xff0c;从而拓宽企业和政府客户的区块链应用范围。 2024年2月22日&#xff0c;瑞士楚格 - BSV区块链协会宣布已经开始对Teranode节点软件进行技术测试&#xff…

【操作系统概念】 第8章:内存管理

文章目录 0.前言8.1 背景8.1.1 基本硬件8.1.2 地址绑定8.1.3 逻辑地址空间和物理地址空间8.1.4 动态加载&#xff08;dynamic loading&#xff09;8.1.5 动态链接&#xff08;dynamically linking&#xff09;与共享库 8.3 连续内存分配&#xff08;contiguous memory allocati…

基于单片机的篮球计分器设计

在当今的体育赛事中,比赛的计分系统对观众和运动员尤为重要,观众可以根据比分的实时显示为自己支持的队伍呐喊助威,运动员更是要靠着计分器来把握比赛的节奏,包括攻防转换、替补换人以及赛间休息等等。因此,为了让比赛进行得更加专业化和流畅化,我们有必要对比赛的计分系…

IDEA快捷键大全,再也不会忘记了 ,建议收藏关注~~

熟练使用 IDEA 快捷键&#xff0c;可以显著提升编码效率。本文汇总了 Windows 系统下 IDEA 的快捷键&#xff0c;非常多&#xff0c;但是没有必有都要记住&#xff0c;仅需要记住下文标注 ✔️ 的必会快捷即可&#xff0c;至于那些使用频率不是很高的快捷键&#xff0c;手动点击…

14:00面试,15:00就出来了,问的问题过于变态了。。。

从小厂出来&#xff0c;没想到在另一家公司又寄了。 到这家公司开始上班&#xff0c;加班是每天必不可少的&#xff0c;看在钱给的比较多的份上&#xff0c;就不太计较了。没想到2月一纸通知&#xff0c;所有人不准加班&#xff0c;加班费不仅没有了&#xff0c;薪资还要降40%…

Elasticsearch:机器学习与人工智能 - 理解差异

作者&#xff1a;来自 Elastic Aditya Tripathi, Jessica Taylor 长期以来&#xff0c;人工智能几乎完全是科幻小说作家的玩物&#xff0c;人类将技术推得太远&#xff0c;以至于它变得活跃起来 —— 正如好莱坞让我们相信的那样 —— 开始造成严重破坏。 令人愉快的东西&#…

pytorch续写tensorboard

模型训练到一半有 bug 停了&#xff0c;可以 resume 继续炼&#xff0c;本篇给出 pytorch 在 resume 训练时续写 tensorboard 的简例&#xff0c;参考 [1-3]&#xff0c;只要保证 writer 接收的 global step 是连着的就行。 Code import numpy as np from torch.utils.tensor…

GO: 快速升级Go版本

由于底层依赖升级了&#xff0c;那我们也要跟着升&#xff0c;go老版本已经不足满足需求了&#xff0c;必须要将版本升级到1.22.0以上 查看当前Go版本 命令查看go版本 go version[rootlocalhost local]# go version go version go1.21.4 linux/amd64 [rootlocalhost local]# …

分享一个开发者武库网站

各种资源信息: 网站地址

数字时代下的内部审计蜕变:探索数字化转型的七大关键领域

写在前面 内部审计是一种独立的、客观的确认和咨询活动&#xff0c;包括鉴证、识别和分析问题以及提供管理建议和解决方案。狭义的数字化转型是指将企业经营管理和业务操作的各种行为、状态和结果用数字的形式来记录和存储&#xff0c;据此再对数据进行挖掘、分析和应用。广义…

Qt添加VTK并绘制图形

文章目录 准备环境使用VS创建Qt Widget项目配置VTK依赖调试C/C链接器 添加vtk窗口测试代码 参考链接&#xff1a; VS2017配置QT环境(详细版)_vs2017 qt-CSDN博客 QT5VTK9.1最新配置方法_qt vtk-CSDN博客 VTK笔记-Qt5.12.11编译VTK9.0.3-QVTKOpenGLNativeWidget-CSDN博客 准…

数字孪生基础开发平台的流程

搭建数字孪生基础开发平台的流程可以分为以下步骤&#xff0c;具体的实施方法和步骤可能会根据具体项目的要求和特点而有所不同。北京木奇移动技术有限公司&#xff0c;专业的软件外包开发公司&#xff0c;欢迎交流合作。 1.需求分析&#xff1a; 确定数字孪生基础开发平台的目…

Find My产品越来越得到市场认可,伦茨科技ST17H6x芯片赋能厂家

苹果发布AirTag发布以来&#xff0c;大家都更加注重物品的防丢&#xff0c;苹果的 Find My 就可以查找 iPhone、Mac、AirPods、Apple Watch&#xff0c;如今的Find My已经不单单可以查找苹果的设备&#xff0c;随着第三方设备的加入&#xff0c;将丰富Find My Network的版图。产…

哪些泛域名ssl证书500元一年送一月

SSL证书是如今数字化时代中重要的一环&#xff0c;随着互联网的发展&#xff0c;单个用户所持有的网站越来越多&#xff0c;因此泛域名SSL证书和多域名SSL证书的签发两越来越多。其中&#xff0c;泛域名SSL证书能够保护主域名以及主域名下所有子域名&#xff0c;它的灵活性和便…

如何批量更改图片的创建时间和修改时间 ? 图片属性更改

在数字时代&#xff0c;图像已经成为我们日常生活中不可或缺的一部分。无论是在社交媒体上分享生活点滴&#xff0c;还是在工作报告中展示数据成果&#xff0c;图像都扮演着至关重要的角色。然而&#xff0c;有时我们可能需要对图像进行一些调整&#xff0c;以更好地满足我们的…