Skip to content

Commit

Permalink
fix:修复 file provider 与拍照问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Qixingchen committed Feb 8, 2017
1 parent 8dd79c5 commit 38eab19
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 58 deletions.
4 changes: 1 addition & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"

compile 'com.github.Qixingchen:RV-Utils:V1.0.1'
compile 'com.github.Qixingchen:RV-Utils:V1.1.3'

compile 'com.github.bumptech.glide:glide:3.7.0'
testCompile 'junit:junit:4.12'
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="moe.xing.getimage_app">

<application
Expand All @@ -15,6 +16,20 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>


<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"
tools:replace="android:resource"/>
</provider>

</application>

</manifest>
76 changes: 28 additions & 48 deletions app/src/main/java/moe/xing/getimage_app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,74 +31,54 @@ protected void onCreate(Bundle savedInstanceState) {
mBinding.recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
mBinding.recyclerView.setAdapter(mAdapter);

final Subscriber<File> fileSubscriber = new Subscriber<File>() {
@Override
public void onCompleted() {
Toast.makeText(MainActivity.this, "complete", Toast.LENGTH_SHORT).show();
}

@Override
public void onError(Throwable e) {
Toast.makeText(MainActivity.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNext(File file) {
mAdapter.addData(file);
}
};


mBinding.singleCorp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
RxGetImage.getInstance().getImage(RxGetImage.MODE_SINGLE_AND_CORP).subscribe(new Subscriber<File>() {
@Override
public void onCompleted() {
Toast.makeText(v.getContext(), "complete", Toast.LENGTH_SHORT).show();
}

@Override
public void onError(Throwable e) {
Toast.makeText(v.getContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNext(File file) {
mAdapter.addData(file);
}
});
RxGetImage.getInstance().getImage(true).subscribe(fileSubscriber);

}
});

mBinding.single.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
RxGetImage.getInstance().getImage(RxGetImage.MODE_SINGLE).subscribe(new Subscriber<File>() {
@Override
public void onCompleted() {
Toast.makeText(v.getContext(), "complete", Toast.LENGTH_SHORT).show();
}

@Override
public void onError(Throwable e) {
Toast.makeText(v.getContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNext(File file) {
mAdapter.addData(file);
}
});
RxGetImage.getInstance().getImage(false).subscribe(fileSubscriber);

}
});

mBinding.multiple.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
RxGetImage.getInstance().getMultipleImage(Integer.MAX_VALUE).subscribe(new Subscriber<File>() {
@Override
public void onCompleted() {
Toast.makeText(v.getContext(), "complete", Toast.LENGTH_LONG).show();
}

@Override
public void onError(Throwable e) {
Toast.makeText(v.getContext(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
}

@Override
public void onNext(File file) {
mAdapter.addData(file);
}
});
RxGetImage.getInstance().getMultipleImage(Integer.MAX_VALUE).subscribe(fileSubscriber);

}
});

mBinding.take.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RxGetImage.getInstance().takeImage(true).subscribe(fileSubscriber);
}
});

}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
android:layout_height="wrap_content"
android:text="获取多图"/>

<Button
android:id="@+id/take"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拍摄并裁剪"/>


</LinearLayout>

Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!--/storage/emulated/0/Android/data/${applicationId}/files/apk/-->
<external-path
name="beta_external_files_path"
path="Android/data/com.sc_edu.jgb"/>

<external-cache-path
name="my_images_external"
path=""/>
<cache-path
name="my_images"
path=""/>
</paths>
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0-beta2'
classpath 'com.android.tools.build:gradle:2.3.0-beta3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.4.0'
classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.5.0'
Expand All @@ -27,8 +27,7 @@ task clean(type: Delete) {
}

ext {
supportLibraryVersion = '25.1.0'
rx_binding_version = '0.4.0'
supportLibraryVersion = '25.1.1'
sdk_version = 25
buildToolsVersion = "25.0.1"
buildToolsVersion = "25.0.2"
}
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
})
testCompile 'junit:junit:4.12'

compile "com.github.Qixingchen:Rx-Utils:V1.1.0"
compile "com.github.Qixingchen:Rx-Utils:V1.2.2"
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
//corp
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.fileprovider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
Expand Down
3 changes: 2 additions & 1 deletion lib/src/main/java/moe/xing/getimage/GetImageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void doTake() {
}
if (takenFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.android.fileprovider",
Init.getApplication().getPackageName() + ".fileProvider",
takenFile);
takeIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
IntentUtils.startIntentForResult(takeIntent, this, TAKE_PHOTO);
Expand Down Expand Up @@ -150,6 +150,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
RxGetImage.getInstance().onError(new Throwable("空文件"), getSubscriberID());
finish();
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
finish();
Expand Down

0 comments on commit 38eab19

Please sign in to comment.