美文网首页
Android备忘录

Android备忘录

作者: 想入飞飞___ | 来源:发表于2016-10-20 18:33 被阅读114次

    常用库Gradle依赖:

     // retrofit2 的gson转换器依赖
    compile 'com.squareup.retrofit2:converter-gson:2.0.1'  
      //retrofit2
    compile 'com.squareup.retrofit2:retrofit:2.0.1'
    //  retrofit2 为RxJava准备的CallAdapter 
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.1'  
    
    //  RxAndroid 
    compile 'io.reactivex:rxandroid:1.1.0'  
    //RxJava
    compile 'io.reactivex:rxjava:1.1.0'  
    
    //Luban 图片压缩框架
    compile 'top.zibin:Luban:1.0.5'
    
    
    仿美团等选择城市列表demo
    https://github.com/zaaach/CityPicker
    
    获取照片(拍照或从相册、文件中选择)、裁剪图片、压缩图片的开源工具库
    https://github.com/crazycodeboy/TakePhoto
    
    

    如何在Android Studio安装so文件?

    1. 在app>>src>>main 目录下建立 jniLibs文件夹,jniLibs文件夹下放so文件;
    2. 在app的buid.gradle文件中添加SO库目录配置
     android {
         sourceSets {
             main.jniLibs.srcDirs = ['libs']
        }
     }
    

    如何在android 6.0 添加HttpClient库?

    在app的build.gradle文件添加配置信息useLibrary 'org.apache.http.legacy'声明编译时依赖

    android {
     compileSdkVersion 23
     buildToolsVersion "23.0.2"
     useLibrary 'org.apache.http.legacy'
    }
    

    注:如果在build.gradle文件中useLibrary 'org.apache.http.legacy'这句话报错,可将该jar直接放到libs目录下即可。

    常用代码

    android 6.0 通知

    NotificationManager notificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent pi = PendingIntent.getActivity(mContext, 0,
            new Intent(MainActivity.this, MainActivity.class), 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
            .setTicker("更新啦")
            .setContentTitle("标题")
            .setContentText("内容")
            .setSmallIcon(R.drawable.ic_launcher);
    Notification notification = builder.build();
    notificationManager.notify(0, notification);
    

    打开Android 相册

    Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
           intent.setType("image/*");
    

    打开Android相机

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, PathToUri(imgPath));
    

    相关文章

      网友评论

          本文标题:Android备忘录

          本文链接:https://www.haomeiwen.com/subject/uezfuttx.html