-1

I have seen some of example where other application can start my application by package name. Due to security reason I want to prevent this kind of access for other application.

I want to prevent this (Open another application from your own (intent)) kind of acess

Edit

For Example, If thirdparty application knows my application's package name they can launch my app from their application like this way,

Intent i;
PackageManager manager = getPackageManager();
try {
    i = manager.getLaunchIntentForPackage("app package name");
    if (i == null)
        throw new PackageManager.NameNotFoundException();
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);
} catch (PackageManager.NameNotFoundException e) {   
}

Now to prevent this, i have added export = "false" in my launching activity as well as added permission to lauching activity. Now due to this, it is preventing thirdparty app to launch my application but android OS launcher is also not able to launch application.

Community
  • 1
  • 1
Ravi Bhojani
  • 944
  • 1
  • 11
  • 24

3 Answers3

1

I imagine if you don't provide the launch intent in your Android manifest, other apps (including your homescreen) won't be able to launch your app.

Ljdawson
  • 11,489
  • 11
  • 41
  • 58
  • Application should be launch via launcher. It's just that it should not be launched via any third party application. – Ravi Bhojani Oct 09 '13 at 09:13
0

You can try these attributes in manifest:
http://developer.android.com/guide/topics/manifest/activity-element.html#exported http://developer.android.com/guide/topics/manifest/service-element.html#exported http://developer.android.com/guide/topics/manifest/receiver-element.html#exported http://developer.android.com/guide/topics/manifest/provider-element.html#exported

As also mentioned in those links, you can try another approach by using permission with the protectionLevel = signature
http://developer.android.com/guide/topics/manifest/permission-element.html#plevel

Binh Tran
  • 2,438
  • 1
  • 20
  • 18
0

I hope below solution by comparing package name will help you protecting your activity to be launched by other app.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ComponentName componentName = this.getCallingActivity();
    if(componentName == null) {
        finish();
    } else if("<intended package name>".equals(componentName.getPackageName())) {
         finish();
        } else {
            String data = getIntent().getDataString();
            ...
        }
    }
}

Above solution is base on below assumption:

  • Only one app with a particular package name can exist on Google Play.
  • If a user tries to install an app whose package name already exists on the device, the installation either will fail or will overwrite the previously installed app.
Ashwin
  • 118
  • 1
  • 8