2016-08-09 65 views
-1

Ich bekomme ständig eine Sicherheitsausnahme, wenn ich versuche, eine andere Aktivität als meine MainActivity zu starten, Code funktioniert gut, wenn ich meine MainActivity starte, aber löst eine Ausnahme aus, wenn ich versuche, eine andere Aktivität als MainActivity zu starten, ich habe nach Antworten gesucht und eine Lösung gefunden, um --android: exported = "true" - in meinem Manifest zu platzieren, aber das hilft nicht dem Problem, vor dem ich stehe Hilfe wird bis jetzt sehr geschätzt.Java.lang.securityException: Berechtigungsverweigerung: Start Absicht

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

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

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:exported="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name=".MainActivity"> 
      <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=".registration" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_name" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_securityquestions" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_id" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_cellnumber" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_email" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_password" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".Maindrawer" 
      android:label="@string/title_activity_maindrawer" 
      android: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:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    package="com.infamuspips.cess"> 

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

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:exported="true" 
     android:theme="@style/AppTheme"> 
     <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=".MainActivity" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_name" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_securityquestions" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_id" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_cellnumber" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_email" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".reg_password" 
      android:label="@string/app_name"></activity> 
     <activity 
      android:name=".Maindrawer" 
      android:label="@string/title_activity_maindrawer" 
      android:theme="@style/AppTheme"></activity> 
    </application> 

</manifest> 

.

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

import android.app.ProgressDialog; 
import android.content.ContentValues; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.AsyncTask; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.test.suitebuilder.annotation.Suppress; 
import android.text.Editable; 
import android.text.TextWatcher; 
import android.util.Base64; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.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 android.content.Intent; 
import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.v7.app.AppCompatActivity; 
import android.text.Editable; 
import android.text.TextWatcher; 
import android.view.View; 
import android.widget.Button; 
import android.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=android.intent.action.MAIN cat=[android.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.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:2498) 
08-09 13:59:52.460 220-10439/? W/System.err:  at com.android.server.am.ActivityStack.startActivityMayWait(ActivityStack.java:3095) 
08-09 13:59:52.460 220-10439/? W/System.err:  at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:2298) 
08-09 13:59:52.460 220-10439/? W/System.err:  at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:147) 
08-09 13:59:52.460 220-10439/? W/System.err:  at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1603) 
08-09 13:59:52.460 220-10439/? W/System.err:  at android.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

* bekam eine Lösung -Android zu setzen: exportiert = „true“ - in meinem Manifest * ... aber Sie setzen es in einem zufälligen Ort ... was war die vollständige Antwort das gefunden? sagt es, dieses Attribut in '' Element zu setzen? Hat '' Element '' android: exportiert 'überhaupt? – Selvin

+1

Dank Selvin, es geht durch meine Tag, es funktioniert jetzt gut. Ich schätze, du bekommst keine Antworten, immer gut, um ein wenig zu graben, mein Dank. – Bradley

Antwort

0

ersetzen

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

mit

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

reinigen und bauen Sie Ihr Projekt