Android 암시적 의도 유효성 검사 (Android implicit intents validation)


문제 설명

Android 암시적 의도 유효성 검사 (Android implicit intents validation)

내 애플리케이션에서 데이터를 Excel 파일에 저장하고 사용자에게 다음을 제안합니다.

  1. 장치에서 저장된 Excel 파일 열기;
  2. 파일 관리자에 파일 표시(폴더 포함).
  3. 이메일로 첨부된 파일 보내기(실제로는 이메일 클라이언트를 열고 파일을 첨부).

내 기기에서는 모든 것이 제대로 작동하는 것 같지만 질문은 다음과 같습니다.

  • 이 암시적 의도를 확인하는 방법은 무엇입니까?
  • 사용할 수 있는 Excel 뷰어/파일 관리자/이메일 클라이언트가 없다면?
  • 어떻게 예측해야 합니까?
  • 다른 유효성 검사를 추가해야 합니까?

코드

    /**
     * Opening saved file.
     * 
     * @param file
     *            ‑ File to be opened
     */

    private void openSavedFile(File file) {
        Uri uri = Uri.fromFile(file);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(uri);
        this.startActivity(intent);
    }

    /**
     * Open a file browser and shows the folder which contains the file passed
     * as a parameter.
     * 
     * @param file
     *            ‑ File to be shown in file browser
     */
    public void openFolder(File file) {
        if (file.exists()) {
            file = file.getParentFile();

            Uri selectedUri = Uri.fromFile(file);

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(selectedUri, "resource/folder");
            startActivity(intent);
        }
    }

    /**
     * Sends a file by email in attachment
     * 
     * @param file
     *            ‑ file to be sent
     */
    private void sendReportByMail(File file) {

        Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
        // setting the type
        emailIntent.setData(Uri.parse("mailto:"));

        // the attaching the file
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

        // the mail subject
        emailIntent.putExtra(Intent.EXTRA_SUBJECT, createEmailSubject());

        // starting email intent with chooser
        startActivity(Intent.createChooser(emailIntent, this.getResources()
                .getString(R.string.report_email_chooser)));

    }

참조 솔루션

방법 1:

Check that the implicit intent you fire ,any activity is their to handle that fire intent

PackageManager packageManager = getActivity().getPackageManager();
    if (intent.resolveActivity(packageManager) != null) {
        //Gotactivity to handle intent
        startActivity(intent);
    }   else  {
        Log.d(TAG, "No Intent available to handle action");
    }

(by user4702646santoXme)

참조 문서

  1. Android implicit intents validation (CC BY‑SA 2.5/3.0/4.0)

#android-intent #Android






관련 질문

인텐트를 사용하여 메시지 작성 열기 (Opening create message using an intent)

다른 데이터로 일부 인텐트를 생성하더라도 알림에서 동일한 추가 데이터를 얻습니다. (I get the same extra data from notifications even if I create some intents with different data)

내 앱의 피드백 양식에 채워진 텍스트를 내 이메일 주소로 가져오는 방법은 무엇입니까? 자세한 내용을 참조하십시오 (How to get the text filled in feedback form of my app to my email address? Please see details)

Android 이미지 갤러리 이미지 자르기 및 ImageView 설정 (Android Image Gallery Crop Image and set ImageView)

xamarin에서 Android 활동 간에 데이터를 전달할 수 없습니다. (Can't pass data between android activities in xamarin)

모든 애플리케이션에 대한 Android 앱에서 데이터 공유 (Share Data in android app for all applications)

zxing이 브라우저에서 URL을 열도록 하거나 스캔 후 번호를 다이얼하는 방법 (How to make zxing open a URL in a browser or dial a number after scanning)

Android 암시적 의도 유효성 검사 (Android implicit intents validation)

kaldi 설치 시 libmkl_tbb_thread.so sth 관련 문제 (A problem related to libmkl_tbb_thread.so sth when installing kaldi)

Intent를 통해 데이터 전달 및 수신 (Passing data through Intent and receiving it)

android studio에서 인텐트를 통해 여러 콘텐츠를 보내는 방법 (how can i send multiple contents through intent in android studio)

Kotlin의 다른 EditText 값에 대한 의도 EditText 값 (Intent EditText values to another EditText values in Kotlin)







코멘트