当前位置: 首页 > news >正文

商城网站设计教程自动收录

商城网站设计教程,自动收录,做网站招聘的职业顾问,河南省建设集团有限公司网站android AIDL接口使用 aidl实现新建aidl实现工程build.gradleproguard-rules.pro增加aidl文件 增加aidl实现aidl实现服务打开aidl服务 aidl使用新建aidl使用工程增加aidl文件使用aidl方法 相关回显 aidl实现 新建aidl实现工程 新建一个工程。工程名testaidl。包名com.lxh.tes…

android AIDL接口使用

  • aidl实现
    • 新建aidl实现工程
      • build.gradle
      • proguard-rules.pro
      • 增加aidl文件
    • 增加aidl实现
      • aidl实现服务
      • 打开aidl服务
  • aidl使用
    • 新建aidl使用工程
      • 增加aidl文件
      • 使用aidl方法
  • 相关回显

aidl实现

新建aidl实现工程

新建一个工程。工程名testaidl。包名com.lxh.testaidl。修改配置文件

build.gradle

a
修改sdk配置,修改version,修改生成apk命名,修改编译混淆配置,增加系统签名
文件位置:\testaidl\app
文件名:build.gradle
在这里插入图片描述

plugins {id 'com.android.application'
}
android {compileSdkVersion 30buildToolsVersion "30.0.2"defaultConfig {applicationId "com.lxh.testaidl"minSdkVersion 28targetSdkVersion 30versionCode 1def date = new Date().format("yyyyMMddHHmm" , TimeZone.getTimeZone("GMT+08"))versionName "testaidl-V1.0-"+datetestInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"}android.applicationVariants.all {variant ->variant.outputs.all {outputFileName = new File(defaultConfig.versionName + ".apk");}}signingConfigs {release {storeFile file("../keystore/mykey.jks")storePassword '123456'keyAlias '_mykey'keyPassword '123456'}debug {storeFile file("../keystore/mykey.jks")storePassword '123456'keyAlias '_mykey'keyPassword '123456'}}buildTypes {release {minifyEnabled trueproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'signingConfig signingConfigs.release}}compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}
}dependencies {implementation 'androidx.appcompat:appcompat:1.2.0'implementation 'com.google.android.material:material:1.2.1'implementation 'androidx.constraintlayout:constraintlayout:2.0.1'testImplementation 'junit:junit:4.+'androidTestImplementation 'androidx.test.ext:junit:1.1.2'androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

b
修改build variants中active build variant 从debug改成release
在这里插入图片描述
c
签名文件
文件位置:\testaidl\keystore
文件名:mykey.jks

proguard-rules.pro

增加混淆
文件位置:\testaidl\app
文件名:proguard-rules.pro

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontoptimize
-dontpreverify
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-dontwarn android.support.**
-keep class android.support.annotation.Keep
-keep @android.support.annotation.Keep class * {*;}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <methods>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <fields>;
}
-keepclasseswithmembers class * {
@android.support.annotation.Keep <init>(...);
}
-optimizationpasses 5
-dontusemixedcaseclassnames
-ignorewarnings
-keep class com.lxh.testaidl.USTservice { *; }
-keep public class com.lxh.testaidl.aidl.UST {*;}

增加aidl文件

增加aidl文件
文件位置:testaidl\app\src\main\aidl\com\lxh\testaidl\aidl
文件名:UST.aidl

package com.lxh.testaidl.aidl;interface UST {int installPackage(String filepath,int indicator,String version);}

增加aidl实现

编译一遍,能import aidl出来
import com.lxh.testaidl.aidl.UST;

aidl实现服务

新增service,命名USTservice

package com.lxh.testaidl;import android.app.IntentService;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;import androidx.annotation.Nullable;import com.lxh.testaidl.aidl.UST;/*** create by lxh on 2022/12/12 Time:14:35* tip:*/
public class USTservice extends IntentService {private static final String TAG = "USTservice lxh";@Overrideprotected void onHandleIntent(Intent intent) {Log.i(TAG, "onHandleIntent");if (intent != null) {final String action = intent.getAction();}}public TatvUSTservice() {super("USTservice");Log.i(TAG, "USTservice");}public UST.Stub asBinder = new UST.Stub() {@Overridepublic int installPackage(String filepath, int indicator, String version) throws RemoteException {Log.i(TAG, "installPackage(" + filepath + "," + indicator + "," + version);String callerId = getApplicationContext().getPackageManager().getNameForUid(asBinder.getCallingUid());Log.i(TAG, "Calling App:" + callerId);if (callerId.equals("com.lxh.useraidl")) {//在这里放实际的代码}return 1;}};@Overridepublic void onCreate() {super.onCreate();Log.i(TAG, "onCreate");}@Overridepublic int onStartCommand(@Nullable Intent intent, int flags, int startId) {Log.i(TAG, "onStartCommand");return super.onStartCommand(intent, flags, startId);}@Nullable@Overridepublic IBinder onBind(Intent intent) {Log.i(TAG, "onBind");return asBinder;}@Overridepublic boolean onUnbind(Intent intent) {Log.i(TAG, "onUnbind");return true;}@Overridepublic void onDestroy() {Log.i(TAG, "onDestroy");super.onDestroy();}public int installPackage(String filepath, int indicator, String version) {int value = 0;switch (indicator) {case 1:Log.d(TAG, "");value = 1;break;case 2:value = 0;break;default:break;}return value;}
}

清单中

<queries><package android:name="com.tatv.android.TMC.aidl" /></queries><serviceandroid:name=".USTservice"android:enabled="true"android:exported="true"><intent-filter><action android:name="com.lxh.testaidl.aidl.UST" /><category android:name="android.intent.category.DEFAULT" /></intent-filter></service>

打开aidl服务

b新增开机广播接收BootReceiver,用来打开服务

package com.lxh.testaidl;import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;/*** create by lxh on 2022/12/12 Time:14:33* tip:*/
public class BootReceiver extends BroadcastReceiver {private static final String TAG = "BootReceiver lxh";@Overridepublic void onReceive(Context context, Intent intent) {Log.i(TAG, "onReceive: " + intent.getAction());if (!TextUtils.isEmpty(intent.getAction()) && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {Log.i(TAG, "onReceive: ready sent ");Intent it1 = new Intent("com.lxh.testaidl.aidl.UST");it1.setPackage("com.lxh.testaidl");context.startService(it1);}}
}

清单

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /><receiver android:name=".BootReceiver"android:enabled="true"android:exported="true"><intent-filter android:priority="1000"><action android:name="android.intent.action.BOOT_COMPLETED" /></intent-filter></receiver>

aidl使用

新建aidl使用工程

新建一个工程。工程名useraidl。包名com.lxh.useraidl。

增加aidl文件

增加aidl文件
文件位置:useraidl\app\src\main\aidl\com\lxh\testaidl\aidl
文件名:UST.aidl

package com.lxh.testaidl.aidl;interface UST {int installPackage(String filepath,int indicator,String version);}

使用aidl方法

package com.lxh.useraidl;import androidx.appcompat.app.AppCompatActivity;import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.widget.Button;import com.lxh.testaidl.aidl.UST;
public class MainActivity extends AppCompatActivity {private static final String TAG = "MainActivity lxh";UST tUST;Button button;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);button=findViewById(R.id.button);Intent service = new Intent("com.lxh.testaidl.aidl.UST");service.setPackage("com.lxh.testaidl");bindService(service, connection, Context.BIND_AUTO_CREATE);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {try {tUST.installPackage("1",1,"0");} catch (RemoteException e) {e.printStackTrace();}}});}private ServiceConnection connection = new ServiceConnection(){public void onServiceConnected(ComponentName name, IBinder service){Log.i(TAG, "tUST");tUST = UST.Stub.asInterface(service);}public void onServiceDisconnected(ComponentName name){tUST = null;}};}

相关回显

开机广播:am broadcast -a android.intent.action.BOOT_COMPLETED

2023-09-13 10:22:00.081 15635-15635/com.lxh.testaidl I/BootReceiver lxh: onReceive: android.intent.action.BOOT_COMPLETED
2023-09-13 10:22:00.081 15635-15635/com.lxh.testaidl I/BootReceiver lxh: onReceive: ready sent 
2023-09-13 10:22:00.087 15635-15635/com.lxh.testaidl I/USTservice lxh: USTservice
2023-09-13 10:22:00.092 15635-15635/com.lxh.testaidl I/USTservice lxh: onCreate
2023-09-13 10:22:00.093 15635-15635/com.lxh.testaidl I/USTservice lxh: onStartCommand
2023-09-13 10:22:00.113 15635-15790/com.lxh.testaidl I/USTservice lxh: onHandleIntent
2023-09-13 10:22:00.123 15635-15635/com.lxh.testaidl I/USTservice lxh: onDestroy

运行使用aidl工程

2023-09-13 10:24:07.733 16174-16174/com.lxh.useraidl I/MainActivity lxh: tUST

点击按钮使用aidl方法

2023-09-13 10:24:07.637 15635-15635/com.lxh.testaidl I/USTservice lxh: USTservice
2023-09-13 10:24:07.642 15635-15635/com.lxh.testaidl I/USTservice lxh: onCreate
2023-09-13 10:24:07.643 15635-15635/com.lxh.testaidl I/USTservice lxh: onBind
2023-09-13 10:25:23.618 15635-15667/com.lxh.testaidl I/USTservice lxh: installPackage(1,1,0
2023-09-13 10:25:23.619 15635-15667/com.lxh.testaidl I/USTservice lxh: Calling App:com.lxh.useraidl
http://www.hengruixuexiao.com/news/14566.html

相关文章:

  • 中山网站建设工作室windows优化大师怎么使用
  • 省建设厅执业资格注册中心网站企业网站建设目标
  • 武汉北京网站建设手机百度官网首页
  • 中山手机建网站整站seo技术搜索引擎优化
  • 如何自己做视频网站橙子建站
  • pb 做网站网络销售的好处和意义
  • 教育培训营销型网站建设哪家好搜索引擎营销是什么
  • 武汉有个人做网站的如何在百度上开店铺
  • 武汉h5网站设计重庆百度seo整站优化
  • wordpress 安装目录北京seo服务商
  • 网站建设公司需要什么公司在百度怎么推广
  • 自己做时时彩网站网站开发公司哪家好
  • 黄石市下陆区建设管理局网站百度平台商家客服电话
  • 哇塞fm网站维护盘多多搜索引擎入口
  • 理财公司网站建设方案标题优化
  • 提供网站技术seo引擎搜索
  • 免费公开api接口大全网站seo的优化怎么做
  • 珠海市城市建设档案馆网站网络推广宣传
  • 深圳市佳简几何工业设计有限公司百度快速排名优化工具
  • ps怎么做网站图片樱桃磁力bt天堂
  • php网站开发需要什么抖音搜索引擎优化
  • 网站设置为默认主页搜索引擎推广方法
  • 深圳积分商城网站建设seo资讯
  • 济南刚刚发生的大事网站内部seo优化包括
  • 织梦电影网站免费模板拉新推广平台有哪些
  • 用c语言做公司网站护肤品推广软文
  • 企业网站建设费怎么入账seo和sem的区别是什么?
  • 上海网站建设哪家便宜上海网站搜索引擎优化
  • 淄博网站建设设计以下属于网站seo的内容是
  • 苏州建设银行招聘网站图片外链生成工具