October 26, 2024
Chicago 12, Melborne City, USA
Android

error: cannot find symbol String bigImage = getIntent.getStringExtra(OneSignalPush.EXTRA_IMAGE);


I have update my question but my code is toolong i hv cut some part but important part is inside the question

error: cannot find symbol
String bigImage = getIntent.getStringExtra(OneSignalPush.EXTRA_IMAGE);
^
symbol: variable OneSignalPush
location: class Tools

I tried to build apk but i get that errors, My expectation is to build apk to see it or to run it in android studio


    btnFavorite.setOnClickListener(v -> {
        if (isDetailView) {
            if (isOffline) {
                ((ActivityFavoriteDetail) activity).onFavoriteClicked(id, title, category, content, published);
            } else {
                ((ActivityPostDetail) activity).onFavoriteClicked(id, title, category, content, published);
            }
        } else {
            List<Post> posts = dbFavorite.getFavRow(id);
            if (posts.size() == 0) {
                dbFavorite.AddToFavorite(new Post(id, title, category, content, published));
                Snackbar.make(parentView, activity.getString(R.string.msg_favorite_added), Snackbar.LENGTH_SHORT).show();
                imgFavorite.setImageResource(R.drawable.ic_favorite_grey);

            } else {
                if (posts.get(0).getId().equals(id)) {
                    dbFavorite.RemoveFav(new Post(id));
                    Snackbar.make(parentView, activity.getString(R.string.msg_favorite_removed), Snackbar.LENGTH_SHORT).show();
                    imgFavorite.setImageResource(R.drawable.ic_favorite_outline_grey);
                }
            }
        }
        mBottomSheetDialog.dismiss();
    });

    btnShare.setOnClickListener(v -> {
        Tools.shareArticle(activity, title, url);
        mBottomSheetDialog.dismiss();
    });

    btnLaunch.setOnClickListener(v -> {
        activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        mBottomSheetDialog.dismiss();
    });

    btnReport.setOnClickListener(v -> {
        Tools.sendReport(activity, sharedPref.getEmailFeedbackAndReport(), title, "");
        mBottomSheetDialog.dismiss();
    });

    btnFeedback.setOnClickListener(v -> {
        Tools.sendFeedback(activity, sharedPref.getEmailFeedbackAndReport());
        mBottomSheetDialog.dismiss();
    });

    btnClose.setOnClickListener(v -> mBottomSheetDialog.dismiss());

    if (this.sharedPref.getIsDarkTheme()) {
        this.mBottomSheetDialog = new BottomSheetDialog(activity, R.style.SheetDialogDark);
    } else {
        this.mBottomSheetDialog = new BottomSheetDialog(activity, R.style.SheetDialogLight);
    }
    this.mBottomSheetDialog.setContentView(view);

    mBottomSheetDialog.show();
    mBottomSheetDialog.setOnDismissListener(dialog -> mBottomSheetDialog = null);

    dbFavorite = new DbFavorite(activity);
    List<Post> posts = dbFavorite.getFavRow(id);
    if (posts.size() == 0) {
        txtFavorite.setText(activity.getString(R.string.favorite_add));
        imgFavorite.setImageResource(R.drawable.ic_favorite_outline_grey);
    } else {
        if (posts.get(0).id.equals(id)) {
            txtFavorite.setText(activity.getString(R.string.favorite_remove));
            imgFavorite.setImageResource(R.drawable.ic_favorite_grey);
        }
    }

}

public static void displayPostDescription(Activity activity, WebView webView, String htmlData, FrameLayout viewContainer, SharedPref sharedPref) {
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.getSettings().setDefaultTextEncodingName("UTF-8");
    webView.setFocusableInTouchMode(false);
    webView.setFocusable(false);

    if (!Config.ENABLE_TEXT_SELECTION) {
        webView.setOnLongClickListener(v -> true);
        webView.setLongClickable(false);
    }

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    WebSettings webSettings = webView.getSettings();
    if (sharedPref.getFontSize() == 0) {
        webSettings.setDefaultFontSize(Constant.FONT_SIZE_XSMALL);
    } else if (sharedPref.getFontSize() == 1) {
        webSettings.setDefaultFontSize(Constant.FONT_SIZE_SMALL);
    } else if (sharedPref.getFontSize() == 2) {
        webSettings.setDefaultFontSize(Constant.FONT_SIZE_MEDIUM);
    } else if (sharedPref.getFontSize() == 3) {
        webSettings.setDefaultFontSize(Constant.FONT_SIZE_LARGE);
    } else if (sharedPref.getFontSize() == 4) {
        webSettings.setDefaultFontSize(Constant.FONT_SIZE_XLARGE);
    } else {
        webSettings.setDefaultFontSize(Constant.FONT_SIZE_MEDIUM);
    }

    String bgParagraph;
    String mimeType = "text/html; charset=UTF-8";
    String encoding = "utf-8";

    if (sharedPref.getIsDarkTheme()) {
        bgParagraph = "<style type=\"text/css\">body{color: #eeeeee;} a{color:#ffffff; font-weight:bold;}";
    } else {
        bgParagraph = "<style type=\"text/css\">body{color: #000000;} a{color:#1e88e5; font-weight:bold;}";
    }

    String fontStyleDefault = "<style type=\"text/css\">@font-face {font-family: MyFont;src: url(\"file:///android_asset/font/custom_font.ttf\")}body {font-family: MyFont; font-size: medium; overflow-wrap: break-word; word-wrap: break-word; -ms-word-break: break-all; word-break: break-all; word-break: break-word; -ms-hyphens: auto; -moz-hyphens: auto; -webkit-hyphens: auto; hyphens: auto;}</style>";

    String textDefault = "<html><head>"
            + fontStyleDefault
            + "<style>img{max-width:100%;height:auto;border-radius:8px;margin-top:8px;margin-bottom:8px;} figure{max-width:100%;height:auto;} iframe{width:100%;}</style> "
            + bgParagraph
            + "</style></head>"
            + "<body>"
            + Tools.parseHtml(htmlData)
            + "</body></html>";

    String textRtl = "<html dir="rtl"><head>"
            + fontStyleDefault
            + "<style>img{max-width:100%;height:auto;border-radius:8px;margin-top:8px;margin-bottom:8px;} figure{max-width:100%;height:auto;} iframe{width:100%;}</style> "
            + bgParagraph
            + "</style></head>"
            + "<body>"
            + Tools.parseHtml(htmlData)
            + "</body></html>";

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            final boolean isImage = url.endsWith(".jpg") || url.endsWith(".jpeg") || url.endsWith(".png") || url.endsWith(".gif");
            if (sharedPref.openLinkInsideApp()) {
                if (url.startsWith("http://") || url.startsWith("https://")) {
                    Intent intent;
                    if (isImage) {
                        intent = new Intent(activity, ActivityImageDetail.class);
                        intent.putExtra("image", url);
                    } else {
                        if (url.contains("play.google.com") || url.contains("?target=external")) {
                            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        } else {
                            intent = new Intent(activity, ActivityWebView.class);
                            intent.putExtra("title", "");
                            intent.putExtra("url", url);
                        }
                    }
                    activity.startActivity(intent);
                }
            } else {
                Intent intent;
                if (isImage) {
                    intent = new Intent(activity, ActivityImageDetail.class);
                    intent.putExtra("image", url);
                } else {
                    intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                }
                activity.startActivity(intent);
            }

            return true;
        }
    });

    BannerAdView bannerAdView = activity.findViewById(R.id.bannerAdView);

    webView.setWebChromeClient(new WebChromeClient() {
        public void onShowCustomView(View view, CustomViewCallback callback) {
            super.onShowCustomView(view, callback);
            webView.setVisibility(View.INVISIBLE);
            bannerAdView.setVisibility(View.GONE);
            viewContainer.setVisibility(View.VISIBLE);
            viewContainer.addView(view);
            Tools.darkNavigation(activity);
        }

        public void onHideCustomView() {
            super.onHideCustomView();
            webView.setVisibility(View.VISIBLE);
            bannerAdView.setVisibility(View.VISIBLE);
            viewContainer.setVisibility(View.GONE);
            Tools.lightNavigation(activity);
        }
    });

    webView.getSettings().setMediaPlaybackRequiresUserGesture(false);

    if (sharedPref.getIsEnableRtlMode()) {
        webView.loadDataWithBaseURL(null, textRtl, mimeType, encoding, null);
    } else {
        webView.loadDataWithBaseURL(null, textDefault, mimeType, encoding, null);
    }
}

public static void shareArticle(Activity activity, String title, String url) {
    SharedPref sharedPref = new SharedPref(activity);
    String content = Html.fromHtml(activity.getResources().getString(R.string.app_share)).toString();
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    if (sharedPref.getIsShowViewOnSiteMenu()) {
        intent.putExtra(Intent.EXTRA_TEXT, title + "\n" + url + "\n\n" + content + "\n" + "https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
    } else {
        intent.putExtra(Intent.EXTRA_TEXT, title + "\n\n" + content + "\n" + "https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID);
    }
    intent.setType("text/plain");
    activity.startActivity(intent);
}

public static void sendReport(Context activity, String email, String title, String reason) {
    String str;
    try {
        str = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:"));
        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
        intent.putExtra(Intent.EXTRA_SUBJECT, "Report " + title + " in the " + activity.getResources().getString(R.string.app_name));
        intent.putExtra(Intent.EXTRA_TEXT, "Device OS : Android \n Device OS version : " +
                Build.VERSION.RELEASE + "\n App Version : " + str + "\n Device Brand : " + Build.BRAND +
                "\n Device Model : " + Build.MODEL + "\n Device Manufacturer : " + Build.MANUFACTURER + "\n" + "Reason : " + reason);
        try {
            activity.startActivity(Intent.createChooser(intent, "Report"));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(activity.getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

public static void sendFeedback(Context activity, String email) {
    String str;
    try {
        str = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionName;
        Intent intent = new Intent(Intent.ACTION_SENDTO);
        intent.setData(Uri.parse("mailto:"));
        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
        intent.putExtra(Intent.EXTRA_SUBJECT, "Feedback for " + activity.getResources().getString(R.string.app_name));
        intent.putExtra(Intent.EXTRA_TEXT, "Device OS : Android \n Device OS version : " +
                Build.VERSION.RELEASE + "\n App Version : " + str + "\n Device Brand : " + Build.BRAND +
                "\n Device Model : " + Build.MODEL + "\n Device Manufacturer : " + Build.MANUFACTURER + "\n" + "Message : ");
        try {
            activity.startActivity(Intent.createChooser(intent, "Send feedback"));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(activity.getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

public static void openAssetActivity(Context context, String title, String fileName) {
    Intent intent = new Intent(context, ActivityWebView.class);
    intent.putExtra("title", title);
    intent.putExtra("file_name", fileName);
    context.startActivity(intent);
}

public static String parseHtml(String htmlData) {
    if (htmlData != null && !htmlData.trim().equals("")) {
        return htmlData.replace("", "");
    } else {
        return "";
    }
}

public static void notificationOpenHandler(Context context, Intent getIntent) {
    SharedPref sharedPref = new SharedPref(context);
    String id = getIntent.getStringExtra(OneSignalPush.EXTRA_ID);
    String title = getIntent.getStringExtra(OneSignalPush.EXTRA_TITLE);
    String message = getIntent.getStringExtra(OneSignalPush.EXTRA_MESSAGE);
    String bigImage = getIntent.getStringExtra(OneSignalPush.EXTRA_IMAGE);
    String launchUrl = getIntent.getStringExtra(OneSignalPush.EXTRA_LAUNCH_URL);
    String uniqueId = getIntent.getStringExtra(OneSignalPush.EXTRA_UNIQUE_ID);
    String postId = getIntent.getStringExtra(OneSignalPush.EXTRA_POST_ID);
    String link = getIntent.getStringExtra(OneSignalPush.EXTRA_LINK);
    if (getIntent.hasExtra("unique_id")) {
        if (postId != null && !postId.equals("")) {
            if (!postId.equals("0")) {
                Intent intent = new Intent(context, ActivityPostDetail.class);
                intent.putExtra("post_id", postId);
                context.startActivity(intent);
                sharedPref.savePostId(postId);
            }
        }
        if (link != null && !link.equals("")) {
            if (!link.equals("0")) {
                if (link.contains("play.google.com") || link.contains("?target=external")) {
                    context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
                } else {
                    Intent intent = new Intent(context, ActivityWebView.class);
                    intent.putExtra("title", title);
                    intent.putExtra("url", link);
                    context.startActivity(intent);
                }
            }
        }
    }
}



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video