Android opens application without enough permission - android

I am starting to develop in Android and I am trying to understand Permissions, however the apps I made are not working and the "Dangerous" app is being opened even if the opener app doesn't have the required permissions to open it.
Dangerous manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.second_dangerousapp"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.dangerous_app.permission.DANGEROUS_ACTIVITY"
android:label="#string/label_dangerousActivity"
android:description="#string/description_dangerousActivity"
android:permissionGroup="android.permission-group.APP_INFO" >
</permission>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.second_dangerousapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.DANGEROUS_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
The app itself is a simple textview with text.
Then the opener app
Permissions manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.second_permissions"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.second_permissions.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And the code of the main activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnOpen = (Button) findViewById(R.id.buttonOpen);
btnOpen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent open = new Intent("android.intent.action.DANGEROUS_ACTIVITY");
startActivity(open);
}
});
}
What I am doing wrong. Cause right now the permission app shouldn't be able to open the dangerous app as it doesn't have the required permission.

Cause right now the permission app shouldn't be able to open the dangerous app as it doesn't have the required permission.
You are not defending anything in your app with the custom permission. Just having a <permission> element does nothing, other than define the permission. You also need to apply the permission somewhere, such as via an android:permission attribute on your <activity>.
You may also want to read this blog post about some unexpected behavior with respect to custom permissions.

Related

Cannot start another Activity of another Application

I have a problem: I want to start an Activity from another application and for that I did the following:
public void startMyActivity(View view){
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.package", "com.package.MyActivity"));
startActivity(intent);
}
But I get the error: Unable to find explicit activity com.package/com.package.MyActivity. Also I declared the MyActivity as activity in the manifest file and I still get the same error. What am I doing wrong? Thanks!
Manifest file of the application A(from which I want to start the activity):
<?xml version="1.0" encoding="utf-8"?>
package="com.example.appA"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
and this is the Manifest file of the application B(which contains the activity that should be started):
<?xml version="1.0" encoding="utf-8"?>
package="com.mypackage.package.appB"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.package.MyPackage"
android:label="#string/title" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Ok so I found my solution. It is a bit frustrating. So.. I tried all the thinks that you guys suggested(I appreciate that) but nothing worked. So my thoughts guided me to use the adb shell to see how it is my application B named and I found out that it is not only com.package, but it's com.mypackage.package(the name mypackage/pakcage are not relevant, only for example purposes). After that I checked the manifest for the application B and saw that the "package" attribute has as value com.mypackage.package. Thank you again!

Missing Android Icon

I've edited and added features from a programme which has involved adding another class (not activity class) since then when I load the app onto my android device I cannot see an icon appear but the app appears in the Application Manager. I have no errors showing and have commented out each section of the new class to turn it back to the original app. Could anyone tell me whether the problem is most likely to be in the manifest, the main.xml or the activity class? Or if they have come across a similar problem?
Cannot publish code due to company policy.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myAppName" <!-- real package name cannot be supplied -->
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="com.example.MyAppName.ProviderClassName"
android:authorities="com.example.MyAppName.ProviderClassName"
/>
</application>
</manifest>

Android app activity launches when launching from another app activity but doesn't launch on its on.

so i made 2 apps and i wanted to run the activity of one app from the activity of the other app. i can do that by passing a intent from the first app to start the second app. we were required to have a permission tag in activity to do that and which works. but the only situation it doesnt work is when i try running the second app activity(which is the one im talking about). i know it doenst run because of the permission that i set but i was just wondering is there a way to still run the main activity of the second app on its on rather then running it from another app.
first app manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lab08a_awahla"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.example.DANGEROUS_ACTION" />
<permission
android:name="com.example.DANGEROUS_ACTION"
android:label="perimission"
android:protectionLevel="dangerous" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.lab08a_awahla.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
first app java code:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clicking(View view){
Intent i=new Intent();
i.setAction("com.example.DANGEROUS_ACTION");
startActivity(i);
}
}
second app manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lab08b_awahla"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.example.DANGEROUS_ACTION" />
<permission
android:name="com.example.DANGEROUS_ACTION"
android:label="perimission"
android:protectionLevel="dangerous" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.lab08b_awahla.MainActivity"
android:label="#string/app_name"
android:permission="com.example.DANGEROUS_ACTION" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.example.DANGEROUS_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
so i can launch the activity from the first application activity but second application activity doesn't launch on its on. i thinks its because of the permission tag under activity. when i install it on my device it says "app is not installed". if someone can help me with it i would really appreciate it. thanks
Unless you get rid of the android:permission="com.example.DANGEROUS_ACTION" from the second app's main activity, you can't launch the app on its own. Because as per your manifest file, home screen app need to have android:permission="com.example.DANGEROUS_ACTION" permission to launch the app which is false in your case.

Export Problems - to .apk

App works fine when tested from Eclipse on phone via USB/Sync, when I try and Export it to an .apk, the Manifest.xml looses track of 2 activities under the parent "MasterActvity". Then even the USB/Sync stops working because it can't locate the activities. No memory storage is used, just text displays.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.theoreferenceguide"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.theoreferenceguide.MasterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="TipActivity"></activity> This keeps getting kicked out during .apk
<activity android:name="UccActivity"></activity> This keeps getting kicked out during .apk
</application>
</manifest>
I agree with nicopico. It looks like you are missing the . infront of the activity which tells the manifest that the activity is in the local namespace. Alternatively if TipActivity is in the same namespace as MasterActivity you can also do android:name="com.example.theoreferenceguide.TipActivity"

Unfortunately Message Launcher has stopped

I am making a Android Program to send appointment details for future appointment, I have done my coding and getting everything but whenever i do click on Send button getting error message:
Unfortunately Message Launcher [AppName] has stopped
Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mamlambo.tutorial.sendmessage">
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
>
<activity
android:name="com.mamlambo.tutorial.sendmessage.FormActivity"
android:label="#string/app_name">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
</manifest>
If you are sending sms on Button's click, you need to add SEND_SMS permission to your manifest,
<uses-permission android:name="android.permission.SEND_SMS"/>
Also this post will help you, Send SMS in Android

Categories

Resources