java.lang.SecurityException:Permission Denial:在另一个应用程序上启动Intent

时间:2017-11-12 20:41:14

标签: java android android-studio android-intent

我正在尝试从我的应用程序中打开另一个应用程序(1mg)活动。我通过反编译apk从清单文件中找到了另一个应用程序的类名和包名(1mg)。我究竟做错了什么?此外,如果您还可以帮我检查是否安装了应用程序(1mg),如果没有安装,则应该打开www.1mg.com

摇篮

11-13 02:00:22.590 13163-13163/com.example.nishantsikri.microdoctor E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.nishantsikri.microdoctor, PID: 13163
    java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cmp=com.aranoah.healthkart.plus/.others.AboutUsActivity } from ProcessRecord{894ac0c 13163:com.example.nishantsikri.microdoctor/u0a182} (pid=13163, uid=10182) not exported from uid 10102
        at android.os.Parcel.readException(Parcel.java:1684)
        at android.os.Parcel.readException(Parcel.java:1637)
        at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3115)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1520)
        at android.app.Activity.startActivityForResult(Activity.java:4283)
        at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
        at android.app.Activity.startActivityForResult(Activity.java:4241)
        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
        at android.app.Activity.startActivity(Activity.java:4580)
        at android.app.Activity.startActivity(Activity.java:4548)
        at com.example.nishantsikri.microdoctor.NavigationActivity.onNavigationItemSelected(NavigationActivity.java:122)
        at android.support.design.widget.NavigationView$1.onMenuItemSelected(NavigationView.java:154)
        at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
        at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
        at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
        at android.support.design.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:342)
        at android.view.View.performClick(View.java:5657)
        at android.view.View$PerformClick.run(View.java:22453)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6236)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)

NavigationActivity.java

package com.example.nishantsikri.microdoctor;

import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Button;

public class NavigationActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener {

private Button button1, button2, button3, button4, button5, button6, button7;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle("Trending Topics");

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = getWindow(); // in Activity's onCreate() for instance
        w.setNavigationBarColor(Color.parseColor("#00ACC1"));
    }

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    button1 = (Button) findViewById(R.id.button1);
    button2 = (Button) findViewById(R.id.button2);
    button3 = (Button) findViewById(R.id.button3);
    button4 = (Button) findViewById(R.id.button4);
    button5 = (Button) findViewById(R.id.button5);
    button6 = (Button) findViewById(R.id.button6);
    button7 = (Button) findViewById(R.id.button7);

    button1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(NavigationActivity.this,SleepDisorderActivity.class));
        }
    });
}

@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

//    @Override
//    public boolean onCreateOptionsMenu(Menu menu) {
//        // Inflate the menu; this adds items to the action bar if it is present.
//        getMenuInflater().inflate(R.menu.navigation, menu);
//        return true;
//    }

//    @Override
//    public boolean onOptionsItemSelected(MenuItem item) {
//        // Handle action bar item clicks here. The action bar will
//        // automatically handle clicks on the Home/Up button, so long
//        // as you specify a parent activity in AndroidManifest.xml.
//        int id = item.getItemId();
//
//        //noinspection SimplifiableIfStatement
//        if (id == R.id.action_settings) {
//            return true;
//        }
//
//        return super.onOptionsItemSelected(item);
//    }

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {
        startActivity(new Intent(NavigationActivity.this,SymptomActivity.class));
        finish();
    } else if (id == R.id.nav_gallery) {
        startActivity(new Intent(getApplicationContext(),MapsActivity.class));

    } else if (id == R.id.nav_slideshow) {
        Intent intent = new Intent(Intent.ACTION_MAIN);

        if (intent != null) {
            intent.setClassName("com.aranoah.healthkart.plus","com.aranoah.healthkart.plus.others.AboutUsActivity");
            startActivity(intent);
        }

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
}

1 个答案:

答案 0 :(得分:0)

使用:

解决了这个问题
Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setComponent(new ComponentName("com.aranoah.healthkart.plus","com.aranoah.healthkart.plus.pharmacy.search.autocomplete.SearchActivity"));
        startActivity(intent);

此外,它还要求您添加正确的类名。这一切都取决于你通过另一个应用程序的清单文件多少,并执行命中和试用方法,并希望它可能很快就会解决。