我正在尝试从另一个活动中加载图片,当我点击按钮开始活动时,它会显示黑屏并且从不显示并给我这个警告
Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
这是活动......
public class FinalActivity extends Activity {
private final static String TAG = "ICA";
private ImageView imageViewThumbnail;
protected Bitmap mFilterBitmap;
private int[] mColors;
private String filePath;
private int chooserType;
private boolean isActivityResultOver = false;
private String originalFilePath;
private String thumbnailFilePath;
private String thumbnailSmallFilePath;
Global mGlobal;
ProgressDialog mDialog;
ImageView saveIcon, filterIcon;
String[] frames = {
"frame_1", "frame_2", "frame_3", "frame_4", "frame_5",
"frame_6", "frame_7", "frame_8", "frame_9",
"frame_10", "frame_11", "frame_12", "frame_13",
"frame_14", "frame_15", "frame_16", "frame_17",
"frame_18", "frame_19", "frame_20"};
InterstitialAd mInterstitialAd;
AdRequest mAdRequest;
ImageView mImageViewFrame;
int pos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "Activity Created");
setContentView(R.layout.activity_final);
mGlobal = (Global) getApplicationContext();
imageViewThumbnail = (ImageView) findViewById(R.id.selectedimage);
saveIcon = (ImageView) findViewById(R.id.imageSave);
filterIcon = (ImageView) findViewById(R.id.editImage);
mImageViewFrame = (ImageView) findViewById(R.id.frameimage);
// mInterstitialAd = new InterstitialAd(this);
// mInterstitialAd.setAdUnitId(getApplicationContext().getString(R.string.admob_intersitials));
// mAdRequest= new AdRequest.Builder().build();
// mInterstitialAd.loadAd(mAdRequest);
imageViewThumbnail.setOnTouchListener(new MultiTouchListener());
mDialog = Utils.SetProgressBar(mDialog, FinalActivity.this);
mDialog.dismiss();
loadImage(imageViewThumbnail, mGlobal.getPath());
String result = getIntent().getStringExtra("resultpos");
pos = Integer.parseInt(result);
Log.w("Position===", "" + pos);
String imagevalue = frames[pos];
Log.w("imagename=====++++", "" + imagevalue);
int resID = getResources().getIdentifier(imagevalue, "drawable", getPackageName());
mImageViewFrame.setImageResource(resID);
saveIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// if (mInterstitialAd.isLoaded()) {
// mInterstitialAd.show();
// }
RelativeLayout view = (RelativeLayout) findViewById(R.id.layout);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bm = view.getDrawingCache();
SaveImage(bm);
}
});
filterIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RelativeLayout view = (RelativeLayout) findViewById(R.id.layout);
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bm = view.getDrawingCache();
EditImage(bm);
}
});
}
private void SaveImage(Bitmap finalBitmap) {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/HijabPhoto");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-" + n + ".jpg";
File file = new File(myDir, fname);
if (file.exists()) file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
Toast.makeText(FinalActivity.this, "Image Saved Successfully.....", Toast.LENGTH_SHORT).show();
Log.w("FILE PATH===", file.getPath().toString());
String path = file.getPath().toString();
addImageToGallery(path, FinalActivity.this);
out.flush();
out.close();
// if (mInterstitialAd.isLoaded()) {
// mInterstitialAd.show();
// }
Intent sharin = new Intent(FinalActivity.this,ShareActivity.class);
sharin.putExtra("path",fname);
Log.w("file path",""+file.getPath().toString());
startActivity(sharin);
} catch (Exception e) {
e.printStackTrace();
}
}
private void EditImage(Bitmap finalBitmap) {
String root = Environment.getExternalStorageDirectory().toString();
File myDir = new File(root + "/HijabPhoto");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-" + n + ".jpg";
File file = new File(myDir, fname);
if (file.exists()) file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
Log.w("FILE PATH===", file.getPath().toString());
String path = file.getPath().toString();
addImageToGallery(path, FinalActivity.this);
out.flush();
out.close();
// if (mInterstitialAd.isLoaded()) {
// mInterstitialAd.show();
// }
Intent efficatIntent = new Intent(FinalActivity.this,EffictActivity.class);
efficatIntent.putExtra("path",fname);
Log.w("file path",""+file.getPath().toString());
startActivity(efficatIntent);
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void addImageToGallery(final String filePath, final Context context) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.MediaColumns.DATA, filePath);
context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
}
private void loadImage(ImageView iv, final String path) {
if(!isAirplaneModeOn(this.getApplicationContext())) {
Picasso.with(FinalActivity.this)
.load(Uri.fromFile(new File(path)))
.fit()
.centerInside()
.into(iv, new Callback() {
@Override
public void onSuccess() {
Log.i(TAG, "Picasso Success Loading Thumbnail - " + path);
}
@Override
public void onError() {
Log.i(TAG, "Picasso Error Loading Thumbnail Small - " + path);
}
});
}
else{
//do something else?
}
File image = new File(path);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
engrave(bitmap);
// bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true);
}
public void engrave(Bitmap mOriginalImageView) {
final int width = mOriginalImageView.getWidth();
final int height = mOriginalImageView.getHeight();
Bitmap bitmap;
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(getResources(), mOriginalImageView);
mColors = AndroidUtils.drawableToIntArray(drawable);
OilFilter filter = new OilFilter();
filter.setLevels(1);
filter.setRange(1);
mColors = filter.filter(mColors, width, height);
setModifyView(mColors, width, height);
}
protected void setModifyView(int[] colors, int width, int height) {
// mImageView.setWillNotDraw(true);
if (mFilterBitmap != null) {
mFilterBitmap.recycle();
mFilterBitmap = null;
}
mFilterBitmap = Bitmap.createBitmap(colors, 0, width, width, height, Bitmap.Config.ARGB_8888);
// mImageView.setImageBitmap(mFilterBitmap);
// mImageView.setWillNotDraw(false);
// mImageView.postInvalidate();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
Log.i(TAG, "Saving Stuff");
Log.i(TAG, "File Path: " + filePath);
Log.i(TAG, "Chooser Type: " + chooserType);
outState.putBoolean("activity_result_over", isActivityResultOver);
outState.putInt("chooser_type", chooserType);
outState.putString("media_path", filePath);
outState.putString("orig", originalFilePath);
outState.putString("thumb", thumbnailFilePath);
outState.putString("thumbs", thumbnailSmallFilePath);
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
if (savedInstanceState != null) {
if (savedInstanceState.containsKey("chooser_type")) {
chooserType = savedInstanceState.getInt("chooser_type");
}
if (savedInstanceState.containsKey("media_path")) {
filePath = savedInstanceState.getString("media_path");
}
if (savedInstanceState.containsKey("activity_result_over")) {
isActivityResultOver = savedInstanceState.getBoolean("activity_result_over");
originalFilePath = savedInstanceState.getString("orig");
thumbnailFilePath = savedInstanceState.getString("thumb");
thumbnailSmallFilePath = savedInstanceState.getString("thumbs");
}
}
Log.i(TAG, "Restoring Stuff");
Log.i(TAG, "File Path: " + filePath);
Log.i(TAG, "Chooser Type: " + chooserType);
Log.i(TAG, "Activity Result Over: " + isActivityResultOver);
if (isActivityResultOver) {
populateData();
}
super.onRestoreInstanceState(savedInstanceState);
}
private void populateData() {
Log.i(TAG, "Populating Data");
loadImage(imageViewThumbnail, thumbnailFilePath);
// loadImage(imageViewThumbSmall, thumbnailSmallFilePath);
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i(TAG, "Activity Destroyed");
}
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isAirplaneModeOn(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
} else {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
}
}
任何帮助,请
答案 0 :(得分:3)
在API级别17中弃用了Settings.System.AIRPLANE_MODE_ON。
您可以看到参考here
您必须在isAirplaneModeOn方法上用AIRPLANE_MODE_ON替换Settings.System.AIRPLANE_MODE_ON,导入设置为中的全局的