Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7 #492 提交实验77代码 #1880

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions students/soft1714080902129/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:authorities="edu.hzuapps.androidlabs.soft1714080902129.electricitypaymentsystem.fileProvider666"
android:name="android.support.v4.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.LinearLayout;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;


public class Soft1714080902129Activity extends AppCompatActivity {

public static final int TAKE_PHOTO = 1;
private Uri imageUri;
private LinearLayout bg;
private Button button;
private String url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1557248715893&di=e64b82e55e4f27b1712bab3afc0825be&imgtype=0&src=http%3A%2F%2Fwww.51pptmoban.com%2Fd%2Ffile%2F2012%2F11%2F01%2Fa1f289fb0f6233b02486d2fba8c6f1da.jpg";
Expand Down Expand Up @@ -69,7 +76,54 @@ public void run() {
}).start();
}
});
Button takePhoto = findViewById(R.id.take_photo);
takePhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//创建File对象,用户存储拍照后的图片
File output = new File(getExternalCacheDir(),"output_image.jpg");
try{
if(output.exists()) {
output.delete();
}
output.createNewFile();
}catch(IOException e){
e.printStackTrace();
}
if(Build.VERSION.SDK_INT >= 24){
imageUri = FileProvider.getUriForFile(Soft1714080902129Activity.this,
"edu.hzuapps.androidlabs.soft1714080902129.electricitypaymentsystem.fileProvider666",output);
}
else{
imageUri = Uri.fromFile(output);
}
//启动相机程序
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
startActivityForResult(intent,TAKE_PHOTO);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch(requestCode){
case TAKE_PHOTO:
if(resultCode == RESULT_OK){
try{
Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
bg.setBackground(new BitmapDrawable(bitmap));

}catch (IOException e){
e.printStackTrace();
}
}
break;
default:
break;
}
}

//从网络下载图片
private Bitmap getImage(String url_image) {
Bitmap bmp = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="更换背景" />
<Button
android:id="@+id/take_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拍照"/>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path=""/>
</paths>