有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安卓 Java。lang.securityException:权限拒绝:启动意图

当我尝试启动MainActivity以外的其他活动时,我经常会遇到安全异常,当我启动MainActivity时,代码工作正常,但当我尝试启动MainActivity以外的任何其他活动时,会抛出异常,我一直在寻找答案,并得到了一个解决方案,将-安卓:exported=“true”-放在我的清单中,但这无助于解决我面临的问题,我们将非常感谢迄今为止的任何帮助

Manifest file for launching MainActivity - (Which works)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:tools="http://schemas.安卓.com/tools"
    package="com.infamuspips.cess">

    <uses-permission 安卓:name="安卓.permission.INTERNET"/>
    <uses-permission 安卓:name="安卓.permission.ACCESS_NETWORK_STATE" />
    <uses-permission 安卓:name="安卓.permission.CAMERA" />
    <uses-feature 安卓:name="安卓.hardware.camera" />
    <uses-feature 安卓:name="安卓.hardware.camera.autofocus" />
    <uses-permission 安卓:name="安卓.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        安卓:allowBackup="true"
        安卓:icon="@mipmap/ic_launcher"
        安卓:label="@string/app_name"
        安卓:supportsRtl="true"
        安卓:exported="true"
        安卓:theme="@style/AppTheme">
        <activity 安卓:name=".MainActivity">
            <intent-filter>
                <action 安卓:name="安卓.intent.action.MAIN" />

                <category 安卓:name="安卓.intent.category.LAUNCHER"/>
                <category 安卓:name="安卓.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity
            安卓:name=".registration"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_name"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_securityquestions"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_id"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_cellnumber"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_email"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_password"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".Maindrawer"
            安卓:label="@string/title_activity_maindrawer"
            安卓:theme="@style/AppTheme"></activity>
    </application>

</manifest>

Manifest file for launching registration Activity - (Which don't work)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:tools="http://schemas.安卓.com/tools"
    package="com.infamuspips.cess">

    <uses-permission 安卓:name="安卓.permission.INTERNET"/>
    <uses-permission 安卓:name="安卓.permission.ACCESS_NETWORK_STATE" />
    <uses-permission 安卓:name="安卓.permission.CAMERA" />
    <uses-feature 安卓:name="安卓.hardware.camera" />
    <uses-feature 安卓:name="安卓.hardware.camera.autofocus" />
    <uses-permission 安卓:name="安卓.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        安卓:allowBackup="true"
        安卓:icon="@mipmap/ic_launcher"
        安卓:label="@string/app_name"
        安卓:supportsRtl="true"
        安卓:exported="true"
        安卓:theme="@style/AppTheme">
        <activity 安卓:name=".registration">
            <intent-filter>
                <action 安卓:name="安卓.intent.action.MAIN" />

                <category 安卓:name="安卓.intent.category.LAUNCHER"/>
                <category 安卓:name="安卓.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity
            安卓:name=".MainActivity"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_name"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_securityquestions"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_id"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_cellnumber"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_email"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".reg_password"
            安卓:label="@string/app_name"></activity>
        <activity
            安卓:name=".Maindrawer"
            安卓:label="@string/title_activity_maindrawer"
            安卓:theme="@style/AppTheme"></activity>
    </application>

</manifest>

Here's my MainActivity Class
package com.infamuspips.cess;

import 安卓.app.ProgressDialog;
import 安卓.content.ContentValues;
import 安卓.content.Intent;
import 安卓.net.Uri;
import 安卓.os.AsyncTask;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.os.Bundle;
import 安卓.test.suitebuilder.annotation.Suppress;
import 安卓.text.Editable;
import 安卓.text.TextWatcher;
import 安卓.util.Base64;
import 安卓.util.Log;
import 安卓.view.View;
import 安卓.widget.Button;
import 安卓.widget.EditText;
import 安卓.widget.TextView;
import 安卓.widget.Toast;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.InvalidParameterSpecException;
import java.util.ArrayList;
import java.util.List;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.HttpsURLConnection;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "Encryption";
    EditText editText,username,password;
    Button button;
    TextView cancel,forgot_password;
    static String Username = null;
    static String PassWord = null;
    static String GetUsername = null;
    static String GetPassword = null;
    SecretKey secretKey;
    String cipherText, decryptedText;
    KeyGenerator keyGen;
    Cipher aesCipher;
    FileOutputStream fos;
    byte[] byteDataToEncrypt, byteCipherText, byteDecryptedText;

    TextWatcher textwatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {


            String User = username.getText().toString();
            String Pass = password.getText().toString();


            if (!User.isEmpty() && !Pass.isEmpty()) {
                button.setEnabled(true);

            } else {
                button.setEnabled(false);
            }

        }
        @Override
        public void afterTextChanged(Editable s) {

        }

    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        username = (EditText) findViewById(R.id.username);
        password = (EditText) findViewById(R.id.password);
        editText = (EditText) findViewById(R.id.editText);
        username.addTextChangedListener(textwatcher);
        password.addTextChangedListener(textwatcher);
        button = (Button) findViewById(R.id.logIn);
        cancel = (TextView) findViewById(R.id.LoginCancel);
        forgot_password = (TextView) findViewById(R.id.forgot_password);
        //Set Clickable attributes
        cancel.setClickable(true);
        button.setEnabled(false);
        editText.setEnabled(false);
        //Call Operation Methods
        username.requestFocus();
        //Cancel();
        //Forgot_Password();
        Log_In();


    }

    private void Cancel(){
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(getApplicationContext(),registration.class);
                startActivity(i);
            }
        });

    }
    private void Forgot_Password(){
        forgot_password.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });


    }
    class PerformBackGround extends AsyncTask<Void, Void, String>{
        private ProgressDialog mDialog;

        public PerformBackGround() {
            super();
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mDialog = new ProgressDialog(MainActivity.this);
            mDialog.setMessage("Please wait");
            mDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            mDialog.setProgress(0);
            mDialog.setMax(10);
            mDialog.setCancelable(false);
            mDialog.show();

        }

        @Override
        protected String doInBackground(Void... params) {
            try{

                String link = "http://*************************";

                URL url = new URL(link);
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String result = bufferedReader.readLine();
                return result;

            }catch (Exception e){
                return "Exception" + e.getMessage();
            }
        }

        @Override
        protected void onPostExecute(String result) {
            String jsonStr = result;
            String response;


            if (jsonStr != null){
                try{


                    JSONObject jsonObj = new JSONObject(jsonStr);
                    String User = jsonObj.get("name").toString();
                    String Password = jsonObj.get("surname").toString();

                    mDialog.cancel();
                    if (User.equals(Username) && Password.equals(PassWord)){
                        //String name = jsonObj.get("name").toString();
                        //String Surname = jsonObj.get("surname").toString();
                        response = jsonObj.get("surname").toString();
                        getResponse(response);
                        Intent i = new Intent(getApplicationContext(),Maindrawer.class);
                        startActivity(i);

                    }else{
                        response = "invalid";
                        getResponse(response);
                    }
                }catch (Exception e){
                    mDialog.cancel();
                    e.printStackTrace();
                    response =  "unable";
                    getResponse(response);
                }
            }else{
                mDialog.cancel();
                response = "unconnect";
                getResponse(response);

            }
        }

    }
    private void Log_In(){
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //PerformBackGround bg = new PerformBackGround();
                username = (EditText) findViewById(R.id.username);
                password = (EditText) findViewById(R.id.password);
                String user = username.getText().toString();
                String pass = password.getText().toString();
                Username = user;
                PassWord = pass;
                //addmodules addm =new addmodules();
                //addm.execute();
                Toast.makeText(MainActivity.this, md5(username.getText().toString()), Toast.LENGTH_SHORT).show();


                Intent i = new Intent(getApplicationContext(),Maindrawer.class);
                startActivity(i);

                username.getText().clear();
                password.getText().clear();

            }
        });
    }
    public String md5(String text) {
        try {
            // Create MD5 Hash
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(text.getBytes());
            byte messageDigest[] = digest.digest();

            // Create Hex String
            StringBuffer hexString = new StringBuffer();
            for (int i=0; i<messageDigest.length; i++)
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            return hexString.toString();

        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}

}

Here's my registration Activity - (Which doesn't launch & throws an exception
)
package com.infamuspips.cess;

import 安卓.content.Intent;
import 安卓.os.Bundle;
import 安卓.support.annotation.Nullable;
import 安卓.support.v7.app.AppCompatActivity;
import 安卓.text.Editable;
import 安卓.text.TextWatcher;
import 安卓.view.View;
import 安卓.widget.Button;
import 安卓.widget.EditText;

/**
 * Created by Rebone on 4/24/2016.
 */
public class registration extends AppCompatActivity {
    EditText up,  firstname, MidName, lastName,Email,id,password, confirmpassword;
    Button logIn, Register;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.registration);
        up = (EditText) findViewById(R.id.editText1);
        logIn = (Button) findViewById(R.id.reg_login);
        Register = (Button) findViewById(R.id.reg_register);
        up.setEnabled(false);
        Register.setEnabled(true);
        LogIn();
        Register();
    }


    public void LogIn() {
        logIn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(getApplicationContext(), MainActivity.class);
                startActivity(i);
            }
        });
    }
    public void Register() {
        Register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String initial = "Nothing";
                //Modified
                Intent a = new Intent(v.getContext(),reg_name.class);
                //Intent a = new Intent(v.getContext(),reg_password.class);
                a.putExtra("Results", initial);
                startActivity(a);
            }
        });
    }

    }

-

And here's the full stack trace
08-09 13:59:52.444 220-10439/? W/ActivityManager: mDVFSLock.acquire()
08-09 13:59:52.444 220-10439/? W/ActivityManager: Permission denied: checkComponentPermission() owningUid=10118
08-09 13:59:52.444 220-10439/? W/ActivityManager: Permission Denial: starting Intent { act=安卓.intent.action.MAIN cat=[安卓.intent.category.LAUNCHER] flg=0x10000000 cmp=com.infamuspips.cess/.registration } from null (pid=13769, uid=2000) not exported from uid 10118
08-09 13:59:52.460 220-10439/? W/System.err:     at com.安卓.server.am.ActivityStack.startActivityLocked(ActivityStack.java:2498)
08-09 13:59:52.460 220-10439/? W/System.err:     at com.安卓.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3095)
08-09 13:59:52.460 220-10439/? W/System.err:     at com.安卓.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:2298)
08-09 13:59:52.460 220-10439/? W/System.err:     at 安卓.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:147)
08-09 13:59:52.460 220-10439/? W/System.err:     at com.安卓.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1603)
08-09 13:59:52.460 220-10439/? W/System.err:     at 安卓.os.Binder.execTransact(Binder.java:338)
08-09 13:59:52.460 220-10439/? W/System.err:     at dalvik.system.NativeStart.run(Native Method)

共 (1) 个答案

  1. # 1 楼答案

    替换

    <activity android:name=".registration">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
            </activity>
    

    <activity android:name="com.infamuspips.cess.registration">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
    
                        <category android:name="android.intent.category.LAUNCHER"/>
                        <category android:name="android.intent.category.DEFAULT"/>
                    </intent-filter>
                </activity>
    

    清理并重建项目