সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
যখন ব্যবহারকারীরা একটি স্টাইলাস ব্যবহার করে একটি অ্যাপের সাথে আঁকেন, লেখেন বা ইন্টারঅ্যাক্ট করেন, তখন তারা মাঝে মাঝে তাদের হাতের তালু দিয়ে স্ক্রীন স্পর্শ করে। সিস্টেমটি দুর্ঘটনাজনিত পাম স্পর্শ হিসাবে ইভেন্টটিকে স্বীকৃতি এবং খারিজ করার আগে স্পর্শ ইভেন্টটি আপনার অ্যাপে রিপোর্ট করা হতে পারে।
তালুর স্পর্শ সনাক্ত করুন এবং উপেক্ষা করুন
আপনার অ্যাপটিকে অবশ্যই বহিরাগত স্পর্শ ইভেন্টগুলি সনাক্ত করতে হবে এবং সেগুলি উপেক্ষা করতে হবে৷ Android আপনার অ্যাপে একটি MotionEvent অবজেক্ট পাঠানোর মাধ্যমে একটি পাম টাচ বাতিল করে।
আপনার অ্যাপে পাঠানো MotionEvent অবজেক্ট পরীক্ষা করুন। ইভেন্ট বৈশিষ্ট্য (ক্রিয়া এবং পতাকা) নির্ধারণ করতে MotionEvent API ব্যবহার করুন:
একক-পয়েন্টার ইভেন্ট — ACTION_CANCEL চেক করুন। Android 13 এবং উচ্চতর তে, FLAG_CANCELED এর জন্যও পরীক্ষা করুন।
মাল্টি-পয়েন্টার ইভেন্ট — Android 13 এবং উচ্চতর, ACTION_POINTER_UP এবং FLAG_CANCELED চেক করুন।
ACTION_CANCEL এবং ACTION_POINTER_UP / FLAG_CANCELED বৈশিষ্ট্য আছে এমন মোশন ইভেন্টগুলিকে উপেক্ষা করুন৷
valmyView=findViewById<View>(R.id.myView).apply{setOnTouchListener{view,event->// Process motion event.}}
জাভা
ViewmyView=findViewById(R.id.myView);myView.setOnTouchListener((view,event)->{// Process motion event.});
2. ইভেন্ট অ্যাকশন এবং পতাকা নির্ধারণ করুন
ACTION_CANCEL পরীক্ষা করুন, যা সমস্ত API স্তরে একটি একক-পয়েন্টার ইভেন্ট নির্দেশ করে৷ Android 13 এবং পরবর্তীতে, FLAG_CANCELED. এর জন্য ACTION_POINTER_UP চেক করুন৷
কোটলিন
valmyView=findViewById<View>(R.id.myView).apply{setOnTouchListener{view,event->when(event.actionMasked){MotionEvent.ACTION_CANCEL->{//Process canceled single-pointer motion event for all SDK versions.}MotionEvent.ACTION_POINTER_UP->{if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU&&(event.flagsandMotionEvent.FLAG_CANCELED)==MotionEvent.FLAG_CANCELED){//Process canceled multi-pointer motion event for Android 13 and higher.}}}true}}
জাভা
ViewmyView=findViewById(R.id.myView);myView.setOnTouchListener((view,event)->{switch(event.getActionMasked()){caseMotionEvent.ACTION_CANCEL:// Process canceled single-pointer motion event for all SDK versions.caseMotionEvent.ACTION_UP:if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU&&(event.getFlags()&MotionEvent.FLAG_CANCELED)==MotionEvent.FLAG_CANCELED){//Process canceled multi-pointer motion event for Android 13 and higher.}}returntrue;});
3. অঙ্গভঙ্গি পূর্বাবস্থায় ফেরান৷
আপনি একটি পামের স্পর্শ সনাক্ত করার পরে, আপনি অঙ্গভঙ্গির অনস্ক্রিন প্রভাবগুলি পূর্বাবস্থায় ফিরিয়ে আনতে পারেন৷
ACTION_CANCEL : MotionEvent ধ্রুবক যা ইঙ্গিত করে যে একটি অঙ্গভঙ্গি পূর্বাবস্থায় ফেরানো উচিত৷
ACTION_POINTER_UP : MotionEvent ধ্রুবক যা নির্দেশ করে যে প্রথম পয়েন্টার ছাড়া অন্য একটি পয়েন্টার বেড়ে গেছে (অর্থাৎ, ডিভাইস স্ক্রিনের সাথে যোগাযোগ ত্যাগ করেছে)।
FLAG_CANCELED : MotionEvent ধ্রুবক যা নির্দেশ করে যে পয়েন্টার উপরে যাওয়ার কারণে একটি অনিচ্ছাকৃত স্পর্শ ইভেন্ট হয়েছে। Android 13 (API স্তর 33) এবং উচ্চতর ACTION_POINTER_UP এবং ACTION_CANCEL ইভেন্টগুলিতে যোগ করা হয়েছে৷
ফলাফল
আপনার অ্যাপ এখন অ্যান্ড্রয়েড 13 এবং উচ্চতর API লেভেলে মাল্টি-পয়েন্টার ইভেন্টের জন্য এবং সমস্ত API লেভেলে একক-পয়েন্টার ইভেন্টের জন্য পাম টাচ সনাক্ত করতে এবং প্রত্যাখ্যান করতে পারে।
এই নির্দেশিকা ধারণকারী সংগ্রহ
এই নির্দেশিকাটি এই কিউরেট করা কুইক গাইড সংগ্রহের অংশ যা বৃহত্তর অ্যান্ড্রয়েড উন্নয়ন লক্ষ্যগুলি কভার করে:
বড় পর্দার জন্য অপ্টিমাইজ করুন
ট্যাবলেট, ফোল্ডেবল এবং ChromeOS ডিভাইসে একটি অপ্টিমাইজড ব্যবহারকারীর অভিজ্ঞতা সমর্থন করতে আপনার অ্যাপ সক্ষম করুন।
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-02-06 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-02-06 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Reject stylus palm touches\n\n\u003cbr /\u003e\n\nWhen users draw, write, or interact with an app using a stylus, they sometimes\ntouch the screen with the palm of their hands. The touch event might be reported\nto your app before the system recognizes and dismisses the event as an\naccidental palm touch.\n\nIdentify and ignore palm touches\n--------------------------------\n\nYour app must identify extraneous touch events and ignore them. Android cancels\na palm touch by dispatching a [`MotionEvent`](/reference/kotlin/android/view/MotionEvent) object to your app.\n\n- Examine `MotionEvent` objects dispatched to your app. Use the `MotionEvent`\n APIs to determine event properties (actions and flags):\n\n - **Single-pointer events** --- Check for [`ACTION_CANCEL`](/reference/kotlin/android/view/MotionEvent#action_cancel). On Android 13 and higher, also check for [`FLAG_CANCELED`](/reference/kotlin/android/view/MotionEvent#flag_canceled).\n - **Multi-pointer events** --- On Android 13 and higher, check for [`ACTION_POINTER_UP`](/reference/kotlin/android/view/MotionEvent#action_pointer_up) and `FLAG_CANCELED`.\n- Ignore motion events that have the `ACTION_CANCEL` and\n `ACTION_POINTER_UP`/`FLAG_CANCELED` properties.\n\n| **Warning:** Android 12 (API level 32) and lower provide only `ACTION_POINTER_UP` for non-primary multi-pointer events. `FLAG_CANCELED` is not set for cancelable events such as palm touches. As a result, apps cannot determine whether the touch was intended or not on Android 12 and lower.\n\n### 1. Acquire motion event objects\n\nAdd an [`OnTouchListener`](/reference/kotlin/android/view/View.OnTouchListener) to your app: \n\n### Kotlin\n\n```kotlin\nval myView = findViewById\u003cView\u003e(R.id.myView).apply {\n setOnTouchListener { view, event -\u003e\n // Process motion event.\n }\n}\n```\n\n### Java\n\n```java\nView myView = findViewById(R.id.myView);\nmyView.setOnTouchListener( (view, event) -\u003e {\n // Process motion event.\n});\n```\n\n### 2. Determine the event action and flags\n\nCheck for `ACTION_CANCEL`, which indicates a single-pointer event on all API\nlevels. On Android 13 and higher, check `ACTION_POINTER_UP` for `FLAG_CANCELED.` \n\n### Kotlin\n\n```kotlin\nval myView = findViewById\u003cView\u003e(R.id.myView).apply {\n setOnTouchListener { view, event -\u003e\n when (event.actionMasked) {\n MotionEvent.ACTION_CANCEL -\u003e {\n //Process canceled single-pointer motion event for all SDK versions.\n }\n MotionEvent.ACTION_POINTER_UP -\u003e {\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.TIRAMISU &&\n (event.flags and MotionEvent.FLAG_CANCELED) == MotionEvent.FLAG_CANCELED) {\n //Process canceled multi-pointer motion event for Android 13 and higher.\n }\n }\n }\n true\n }\n}\n```\n\n### Java\n\n```java\nView myView = findViewById(R.id.myView);\nmyView.setOnTouchListener( (view, event) -\u003e {\n switch (event.getActionMasked()) {\n case MotionEvent.ACTION_CANCEL:\n // Process canceled single-pointer motion event for all SDK versions.\n case MotionEvent.ACTION_UP:\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.TIRAMISU &&\n (event.getFlags() & MotionEvent.FLAG_CANCELED) == MotionEvent.FLAG_CANCELED) {\n //Process canceled multi-pointer motion event for Android 13 and higher.\n }\n }\n return true;\n});\n```\n\n### 3. Undo the gesture\n\nAfter you've identified a palm touch, you can undo the onscreen effects of the\ngesture.\n\nYour app must keep a history of user actions so that unintended inputs such as\npalm touches can be undone. For an example of how to maintain history, see\n[Implement a basic drawing app](/codelabs/large-screens/advanced-stylus-support#2) in the [Enhance stylus support in an Android\napp](/codelabs/large-screens/advanced-stylus-support) codelab.\n\nKey points\n----------\n\n- [`MotionEvent`](/reference/kotlin/android/view/MotionEvent): Represents touch and movement events. Contains the information necessary to determine whether an event should be disregarded.\n- [`OnTouchListener#onTouch()`](/reference/kotlin/android/view/View.OnTouchListener#ontouch): Receives `MotionEvent` objects.\n- [`MotionEvent#getActionMasked()`](/reference/kotlin/android/view/MotionEvent#getactionmasked): Returns the action associated with a motion event.\n- [`ACTION_CANCEL`](/reference/kotlin/android/view/MotionEvent#action_cancel): `MotionEvent` constant that indicates a gesture should be undone.\n- [`ACTION_POINTER_UP`](/reference/kotlin/android/view/MotionEvent#action_pointer_up): `MotionEvent` constant that indicates a pointer other than the first pointer has gone up (that is, has relinquished contact with the device screen).\n- [`FLAG_CANCELED`](/reference/kotlin/android/view/MotionEvent#flag_canceled): `MotionEvent` constant that indicates that the pointer going up caused an unintentional touch event. Added to `ACTION_POINTER_UP` and `ACTION_CANCEL` events on Android 13 (API level 33) and higher.\n\nResults\n-------\n\nYour app can now identify and reject palm touches for multi-pointer events on\nAndroid 13 and higher API levels and for single-pointer events on all API\nlevels.\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Optimize for large screens\n\nEnable your app to support an optimized user experience on tablets, foldables, and ChromeOS devices. \n[Quick guide collection](/quick-guides/collections/optimize-for-large-screens) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]