从另一个应用程序的活动推出,但在其上不启动时,Android应用程序的活动启动。 [英] Android app activity launches when launching from another app activity but doesn't launch on its on.
问题描述
所以我做了2的应用程序,我想从其他应用程序的活动运行一个应用程序的活动。我能做到这一点通过传递意图从第一个应用程序启动第二个应用程序。我们被要求在活动许可标签做到这一点,它的工作原理。但它不工作的唯一情况是,当我试着运行第二个应用程序的活动(这是一个IM谈论)。我知道这doenst运行,因为我设置的权限,但我只是想知道有没有办法仍然运行在其上而不是从其他应用程序,运行它的第二个应用程序的主要活动。
第一个应用程序清单文件:
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.lab08a_awahla
安卓版code =1
机器人:VERSIONNAME =1.0>
<使用-权限的Android:名称=com.example.DANGEROUS_ACTION/>
<许可
机器人:名称=com.example.DANGEROUS_ACTION
机器人:标签=perimission
安卓的ProtectionLevel =危险/>
<用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =17/>
<应用
机器人:allowBackup =真
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名称=com.example.lab08a_awahla.MainActivity
机器人:标签=@字符串/ APP_NAME>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
第一个应用程序的Java code:
进口android.os.Bundle;
进口android.app.Activity;
进口android.content.Intent;
进口android.view.View;
公共类MainActivity延伸活动{
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
}
公共无效点击(查看视图){
意图I =新意图();
i.setAction(com.example.DANGEROUS_ACTION);
startActivity(ⅰ);
}
}
第二个应用程序清单文件:
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.example.lab08b_awahla
安卓版code =1
机器人:VERSIONNAME =1.0>
<使用-权限的Android:名称=android.permission.ACCESS_WIFI_STATE/>
<使用-权限的Android:名称=com.example.DANGEROUS_ACTION/>
<许可
机器人:名称=com.example.DANGEROUS_ACTION
机器人:标签=perimission
安卓的ProtectionLevel =危险/>
<用途-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =17/>
<应用
机器人:allowBackup =真
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme>
<活动
机器人:名称=com.example.lab08b_awahla.MainActivity
机器人:标签=@字符串/ APP_NAME
机器人:权限=com.example.DANGEROUS_ACTION>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
<意向滤光器>
<作用机器人:名称=com.example.DANGEROUS_ACTION/>
<类机器人:名称=android.intent.category.DEFAULT/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
这样我就可以从第一个应用程序的活动,但第二个应用程序的活动启动活动在其上不启动。我认为,因为在活动的许可标记,它的。当我在我的设备上安装它说:没有安装应用程序。如果有人能帮助我与它我会很AP preciate它。谢谢
除非你摆脱的android:许可=从第二个com.example.DANGEROUS_ACTION
应用程序的主要活动,您不能启动的应用程序自身。因为按你的清单文件,主屏幕应用程序,需要有安卓权限=com.example.DANGEROUS_ACTION
的权限启动应用程序,它是假的,你的情况<。 / P>
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.
这篇关于从另一个应用程序的活动推出,但在其上不启动时,Android应用程序的活动启动。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!