android http常用配置,flutter android开发http请求配置

flutter android 中发送http请求后,默认会报错。需要修改配置文件。

bVcHdgt

bVcHdgC

bVcHdgD

bVcHdgH

network_security_config.xml<?xml version="1.0" encoding="utf-8"?>

AndroidManifest.xml

android:name="io.flutter.app.FlutterApplication"

android:label="flutter_study"

android:icon="@mipmap/ic_launcher"

android:networkSecurityConfig="@xml/network_security_config">

android:name=".MainActivity"

android:launchMode="singleTop"

android:theme="@style/LaunchTheme"

android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

android:hardwareAccelerated="true"

android:windowSoftInputMode="adjustResize">

android:name="flutterEmbedding"

android:value="2" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`Flutter Android JPush Flutter` 是一个结合了 FlutterAndroid 平台的第三方推送服务解决方案,通常指的是使用 Alibaba Cloud 的 JPush 在 Flutter 应用中集成推送通知功能。在 Android配置推送通知权限,你需要确保遵循 Google Play Store 的政策,并按照以下步骤操作: 1. **添加依赖**: 在 `pubspec.yaml` 文件中添加 JPush 的 Flutter 插件依赖: ```yaml dependencies: jpush_flutter: ^latest_version ``` 替换 `latest_version` 为实际的版本号。 2. **注册应用**: 在 AndroidManifest.xml 中添加 JPush 的 Service 和权限声明: ```xml <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 其他可能需要的权限 --> <meta-data android:name="JPUSH_CHANNEL" android:value="your_channel_name" /> <service android:name="cn.jpush.android.service.PushService" android:exported="false"> <intent-filter> <action android:name="cn.jpush.android.intent.REGISTRATION" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.RECEIVE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </service> <service android:name="cn.jpush.android.service.DownloadService" android:exported="false" /> <receiver android:name="cn.jpush.android.service.AlarmReceiver" android:exported="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> ``` 3. **初始化 JPush**: 在 `MainActivity.kt` 或者适当的生命周期管理类中,初始化 JPush 并设置 AppKey: ```kotlin import com.alibaba.jpush.android.PushManager // 替换为你的 AppKey PushManager.setAppKey("your_app_key") ``` 4. **请求用户授权**: 在适当的地方请求用户的通知权限,例如在启动或首次使用时提示用户: ```kotlin val permissionCheck = ContextCompat.checkSelfPermission( applicationContext, Manifest.permission.VIBRATE ) == PackageManager.PERMISSION_GRANTED if (!permissionCheck) { ActivityCompat.requestPermissions( this, arrayOf(Manifest.permission.VIBRATE), MY_PERMISSIONS_REQUEST_VIBRATE ) } ``` 5. **处理权限结果**: 在 `onRequestPermissionsResult` 方法中处理权限请求的结果,确保通知权限已获取: ```kotlin override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { if (requestCode == MY_PERMISSIONS_REQUEST_VIBRATE) { if (grantResults.isNotEmpty() && grantResults == PackageManager.PERMISSION_GRANTED) { // 用户已授予振动权限,继续配置 JPush } else { // 没有授予,显示错误或提示用户 } } } ``` 完成以上步骤后,你应该就能在 Flutter 应用中正常配置并使用 JPush 的推送通知功能了。如果有其他具体问题,请告诉我,我会提供更详细的帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值