خطا‌‌ها‌ی زیر رخ داد:
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 721 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 721 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 752 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 721 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 752 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 721 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 752 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 721 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 721 postParser->parse_message
/showthread.php 1063 build_postbit
Warning [2] preg_replace_callback(): Requires argument 2, 'mwsshcode_check("$1","$2")', to be a valid callback - Line: 197 - File: inc/plugins/mwsshcode.php PHP 7.3.4 (Linux)
File Line Function
[PHP]   errorHandler->error
/inc/plugins/mwsshcode.php 197 preg_replace_callback
/inc/class_plugins.php 139 mwsshcode_run
/inc/class_parser.php 187 pluginSystem->run_hooks
/inc/functions_post.php 752 postParser->parse_message
/showthread.php 1063 build_postbit




رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
ذخیره عکس در گالری
#1
برای ذخیره عکس از متد زیر استفاده می کنم اما از اندروید 5 به بعد برنامه کرش میکنه مشکل کجاست؟.. ممنون
[shcode=java]  public void save_image() {
       File root = android.os.Environment.getExternalStorageDirectory();
       File dir = new File(root.getAbsolutePath() + "/IMAGE_TATAK");
       dir.mkdirs(); // build directory
       file = new File(dir, backgroundImageName);
       if (file.exists())
           file.delete();

       try {
           FileOutputStream outStream = new FileOutputStream(file);
           InputStream ims = getAssets().open("image/" + backgroundImageName);
           Bitmap bitmap = BitmapFactory.decodeStream(ims);

           try {
               ims.close();
               ims = null;
           }
           catch (IOException e) {}
           bitmap = mark(bitmap, null);
           bitmap.compress(Bitmap.CompressFormat.JPEG, 90, outStream);

           outStream.flush();
           outStream.close();
       }
       catch (FileNotFoundException e) {
           e.printStackTrace();
       }
       catch (IOException e) {
           e.printStackTrace();
       }
       sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
       new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
               .setTitleText("Save to gallery")
               .show();

   }
[/shcode]
 در واقع کد زیر باعث کرش میشه

[shcode=java] sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));[/shcode]
پاسخ
تشکر شده توسط:
#2
با کمک این متد مسیر فیزیکی فایل رو استخراج کنید:
[shcode=java]public String getRealPathFromUri(Uri uri) {
String result = "";
String documentID;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
String[] pathParts = uri.getPath().split("/");
documentID = pathParts[pathParts.length - 1];
} else {
String pathSegments[] = uri.getLastPathSegment().split(":");
documentID = pathSegments[pathSegments.length - 1];
}
String mediaPath = MediaStore.Images.Media.DATA;
Cursor imageCursor = getBaseContext().getContentResolver().query(uri, new String[]{mediaPath}, MediaStore.Images.Media._ID + "=" + documentID, null, null);
if (imageCursor != null && imageCursor.moveToFirst()) {
result = imageCursor.getString(imageCursor.getColumnIndex(mediaPath));
imageCursor.close();
}
return result;
}[/shcode]
پاسخ
تشکر شده توسط:
#3
برای ذخیره‌کردن هم باید مجوزهای لازم رو به برنامه بدین. توی نسخه‌های جدید اندروید باید حتماً مجوز بصورت دستی کدنویسی بشه. مثال:
[shcode=java]if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_STORAGE);
}[/shcode]

بعد باید چک کنید مجوز داده شده یا نه:
[shcode=java]@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode)
{
case REQUEST_WRITE_STORAGE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//reload my activity with permission granted or use the features what required the permission
} else {
Toast.makeText(parentActivity, "The app was not allowed to write to your storage. Hence, it cannot function properly. Please consider granting it this permission", Toast.LENGTH_LONG).show();
}
}
}
}[/shcode]
پاسخ
تشکر شده توسط:
#4
این کد رو هم تست کنید:
[shcode=java]sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(Environment.getExternalStorageDirectory().getAbsoultePath())));[/shcode]
پاسخ
تشکر شده توسط:
#5
نیار به کتاب خانه ای هم برای دادن مجوز از کد هست؟
[shcode=java]if(ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
   ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_STORAGE);
}[/shcode]
پاسخ
تشکر شده توسط:
#6
خیر به کتابخانه خاصی احتیاج ندارین.
پاسخ
تشکر شده توسط:




کاربران در حال بازدید این موضوع: 1 مهمان