1

だから私は2つのアプリを作り、他のアプリのアクティビティから1つのアプリのアクティビティを実行したかった. これを行うには、最初のアプリからインテントを渡して 2 番目のアプリを開始します。それを行うには、アクティビティに許可タグが必要であり、それが機能します。しかし、それが機能しない唯一の状況は、2番目のアプリアクティビティ(私が話しているもの)を実行しようとしたときです。設定した許可のために実行されないことはわかっていますが、別のアプリから実行するのではなく、2番目のアプリのメインアクティビティを引き続き実行する方法があるのではないかと思っていました。

最初のアプリ マニフェスト ファイル:

<?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>

最初のアプリの Java コード:

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);
}
}

2 番目のアプリ マニフェスト ファイル:

<?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>

そのため、最初のアプリケーション アクティビティからアクティビティを起動できますが、2 番目のアプリケーション アクティビティは起動しません。アクティビティの下の許可タグが原因だと思います。デバイスにインストールすると、「アプリがインストールされていません」と表示されます。誰かが私を助けてくれれば、本当に感謝しています。ありがとう

4

1 に答える 1

0

2 番目のアプリのメイン アクティビティからを削除しない限りandroid:permission="com.example.DANGEROUS_ACTION"、アプリを単独で起動することはできません。マニフェスト ファイルによると、ホーム画面アプリにandroid:permission="com.example.DANGEROUS_ACTION"は、アプリを起動する権限が必要です。これは、この場合は false です。

于 2013-08-23T19:07:34.780 に答える