Restricting Android Broadcast Receiver from specific app

0 votes

Can I do the same with Broadcast Receiver?

  • app1: sendBroadcast(intent, permission)
  • app2: define permission, use that permission.

To my understanding for using sendBroadcast(intent, permission), the application doesn't need to "use" the permission. Meaning ANY application can send intent to app2. Those permission parameters only checked against app2, to avoid other applications to receive this intent. (If I remove app2, and install fake app2 with the same permission string defined, fake app2 can get intent from app1, which is unexpected)

Is this true?

Now, I can set additional permission:

  • app1: Define permission, use that permission.
  • app2: Receiver restricted only for that permission.

Again, if one removes app1, installs fake app1 with the very same permission, then fake app1 can send fake intent to app2. What can I do to prevent app2 from receiving fake intent?

Jun 16, 2022 in Others by nisha
• 2,210 points
1,328 views

1 answer to this question.

0 votes

 code:

Sender App

MainActivity.java

package com.karthik.apptx;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void OnClickButton(View view) {
        Intent intent = new Intent();
        intent.setAction("com.karthik.apprx");
        intent.putExtra("PACKAGE_NAME", this.getPackageName());
        intent.putExtra("PID", Process.myPid());
        intent.putExtra("DATA", "Hello Karthik");
        intent.setComponent(new ComponentName("com.karthik.apprx", "com.karthik.apprx.AppRxReceiver"));
        sendBroadcast(intent);
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.karthik.apptx">

    <uses-permission android:name="com.karthik.PERMISSION"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppTx">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
answered Jun 16, 2022 by polo
• 1,480 points

Related Questions In Others

0 votes
1 answer

Is it possible to vibrate from broadcast receiver during incoming call?

Hello Android Native Development I have found some ...READ MORE

answered May 9, 2020 in Others by Anadya
1,773 views
0 votes
1 answer

How to remove debug banner from Flutter App?

Hi@akhtar, On your MaterialApp set debugShowCheckedModeBanner to false. The debug banner will also automatically be ...READ MORE

answered Jul 28, 2020 in Others by MD
• 95,460 points
2,296 views
0 votes
1 answer

How to open the Google Play Store directly from my Android application?

By using developer.andriod.com, one can solve this ...READ MORE

answered Feb 8, 2022 in Others by Rahul
• 9,680 points
858 views
0 votes
1 answer

Running docker on Android

According to the documentation, the Android kernel is ...READ MORE

answered Aug 1, 2018 in Docker by Kalgi
• 52,350 points
3,763 views
0 votes
1 answer

Task Canceled Exception while invoking AWS Lambda

I'm guessing either the TaskCanceledException instance is ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,020 points
2,461 views
0 votes
1 answer

Is there a way to run Python on Android?

YES! here’s a barcode scanner written in six ...READ MORE

answered Sep 19, 2018 in Python by Priyaj
• 58,020 points
1,019 views
0 votes
1 answer

How can we get the current location in Android?

First you need to define a LocationListener to handle ...READ MORE

answered Sep 25, 2018 in Java by Parth
• 4,640 points
922 views
0 votes
1 answer

Android open camera from button

you can use the below syntax as ...READ MORE

answered Jun 14, 2022 in Others by polo
• 1,480 points
1,537 views
0 votes
1 answer

extract audio in MP3 format from video in android

Use FFMPEG for android U need to implement a ...READ MORE

answered Jun 16, 2022 in Others by polo
• 1,480 points
1,858 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP