android

android studio连接木木模拟器

  adb connect 127.0.0.1:7555
//如果没有配置 adb 的环境变量,那就找到他的绝对路径,比如 /platform-tools/abd
//然后 
/platform-tools/abd connect 127.0.0.1:7555

推送信息

 NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                Intent intent = new Intent(MainActivity.this, MainActivity.class);
                PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    String channelId = "default";
                    String channelName = "默认通知";
                    //new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH)
                    notificationManager.createNotificationChannel(new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH));
                }
                Notification notification = new NotificationCompat.Builder(MainActivity.this, "default")
                        .setContentTitle("踢踢踢踢踢腿")
                        .setContentText("text")
                        .setDefaults(NotificationCompat.DEFAULT_ALL)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                        .setWhen(System.currentTimeMillis())
                        .setContentIntent(pendingIntent)
                        .setVibrate(new long[]{0, 1000, 1000, 1000})
                        .setLights(Color.GREEN, 1000, 1000)
                        .setAutoCancel(true).build();
                notificationManager.notify(1, notification);

图片显示

//xml
 

//java
 ImageViewCustom iv = findViewById(R.id.ImageView);
 iv.setBitmap(path);


public class ImageViewCustom extends AppCompatImageView {


    public ImageViewCustom(Context context) {
        super(context);
    }

    public ImageViewCustom(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }


    public void setBitmap(String path) {
        AppCompatImageView _self = this;

        new Thread() {
            public void run() {
                try {
                    URL url = new URL(path);
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    int code = connection.getResponseCode();
                    if (code == 200) {
                        InputStream is = connection.getInputStream();
                        Bitmap bitmap = BitmapFactory.decodeStream(is);
                        _self.setImageBitmap(bitmap);
                        is.close();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("TEST", "链接失败");
                }
            }
        }.start();
    }

}

//网络权限


     
    
    
    
    
    
    
        
            
                
                
            
        

  
        
    

拍照 选取图片

    private final ActivityResultLauncher activityResultLauncher = registerForActivityResult(
            new ActivityResultContracts.GetContent(), result -> {
                //视频文件路径
                String videoPath = result.getPath();
            }
    );
//选取视频文件(和选取相册类似)
activityResultLauncher.launch("video/*");
//调用相册选择图片
 activityResultLauncher.launch("image/*");

  //拍照
 private final ActivityResultLauncher mLauncherCamera = registerForActivityResult(new ActivityResultContracts.TakePicturePreview(), result -> {
        //result为拍摄照片Bitmap格式
 });

//启动拍照(注意先检查权限)
//开启拍照,返回结果Bitmap
 mLauncherCamera.launch(null);

 /**
  * 检查权限并拍照。
  * 调用相机前先检查权限。
  */
private void checkPermissionAndCamera() {
        // 申请相机权限的requestCode
        final int PERMISSION_CAMERA_REQUEST_CODE = 0x00000012;
        int hasCameraPermission = ContextCompat.checkSelfPermission(getApplication(),
                Manifest.permission.CAMERA);
        if (hasCameraPermission == PackageManager.PERMISSION_GRANTED) {
            //有调起相机拍照。
            launchCamera();
        } else {
            //没有权限,申请权限。
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, PERMISSION_CAMERA_REQUEST_CODE);
        }
    }


//多选
private final ActivityResultLauncher activityResultLauncher = registerForActivityResult(
            new ActivityResultContracts.OpenMultipleDocuments(), result -> {
                //视频文件路径
                Log.e("OpenMultipleDocuments", result.toString());
            }
 );

//页面跳转
//新建一个Intent(当前Activity, SecondActivity)=====显示Intent
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
//启动Intent
startActivity(intent);

//传值给下一个Activity
String data = "我是上一个Activity中传过来的值";
intent.putExtra("extra_data", data);

 //获取上一个Activity传过来的值
Intent intent = getIntent();
String data = intent.getStringExtra("extra_data");
//将获取的值显示在TextView上
TextView dataTextView = (TextView) findViewById(R.id.data_text_view);
dataTextView.setText(data);
 //点击Button返回上一个Activity
Button backButton = (Button) findViewById(R.id.bank_button);
backButton.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                  finish();
             }
  });

//使用Intent打开系统功能
//调用本地浏览器打开网址
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com"));
intent.setData(Uri.parse("tel:10010"));
startActivity(intent);

//从返回中的Activity中获取值
Intent intent = new Intent(MainActivity.this, ThirdActivity.class);
startActivityForResult(intent, 1);

//返回传值
 Intent intent = getIntent();
 intent.putExtra("data_return", "我是第三个Activity中返回的数据");
 setResult(RESULT_OK, intent);
 finish();

无法下载依赖

//到本地的 gradle.properties ⽂件后,注释掉如下代理⾏即可
#systemProp.https.proxyPort=1086
#systemProp.http.proxyHost=127.0.0.1
#systemProp.https.proxyHost=127.0.0.1
#systemProp.http.proxyPort=1086
image.png

你可能感兴趣的:(android)