Example usage for android.content.pm PackageManager.NameNotFoundException toString

List of usage examples for android.content.pm PackageManager.NameNotFoundException toString

Introduction

In this page you can find the example usage for android.content.pm PackageManager.NameNotFoundException toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:de.arcus.framework.activities.CrashActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_crash);

    // Reads the crash information
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        if (bundle.containsKey(EXTRA_FLAG_CRASH_MESSAGE))
            mCrashMessage = bundle.getString(EXTRA_FLAG_CRASH_MESSAGE);
        if (bundle.containsKey(EXTRA_FLAG_CRASH_LOG))
            mCrashLog = bundle.getString(EXTRA_FLAG_CRASH_LOG);
    } else {/*  w w w .  j a v a  2  s .  c  om*/
        // No information; close activity
        finish();
        return;
    }

    try {
        // Get the PackageManager to load information about the app
        PackageManager packageManager = getPackageManager();
        // Loads the ApplicationInfo with meta data
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);

        if (applicationInfo.metaData != null) {
            // Reads the crash handler settings from meta data
            if (applicationInfo.metaData.containsKey("crashhandler.email"))
                mMetaDataEmail = applicationInfo.metaData.getString("crashhandler.email");
            if (applicationInfo.metaData.containsKey("crashhandler.supporturl"))
                mMetaDataSupportURL = applicationInfo.metaData.getString("crashhandler.supporturl");
        }

        // Gets the app name
        mAppName = packageManager.getApplicationLabel(applicationInfo).toString();
        // Gets the launch intent for the restart
        mLaunchIntent = packageManager.getLaunchIntentForPackage(getPackageName());

    } catch (PackageManager.NameNotFoundException ex) {
        // If this occurs then god must be already dead
        Logger.getInstance().logError("CrashHandler", ex.toString());
    }

    // Set the action bar title
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(getString(R.string.crashhandler_app_has_stopped_working, mAppName));
    }

    // Set the message
    TextView textViewMessage = (TextView) findViewById(R.id.text_view_crash_message);
    if (textViewMessage != null) {
        textViewMessage.setText(mCrashLog);
    }
}

From source file:com.hijacker.SendLogActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setFinishOnTouchOutside(false);//from   www.  jav a  2s  .  co m
    setContentView(R.layout.activity_send_log);

    rootView = findViewById(R.id.activity_send_log);
    userEmailView = (EditText) findViewById(R.id.email_et);
    extraView = (EditText) findViewById(R.id.extra_et);
    progressBar = findViewById(R.id.reportProgressBar);
    console = (TextView) findViewById(R.id.console);
    sendProgress = findViewById(R.id.progress);
    sendCompleted = findViewById(R.id.completed);
    sendBtn = findViewById(R.id.sendBtn);
    sendEmailBtn = findViewById(R.id.sendEmailBtn);

    userEmailView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT) {
                extraView.requestFocus();
                return true;
            }
            return false;
        }
    });

    busybox = getFilesDir().getAbsolutePath() + "/bin/busybox";
    stackTrace = getIntent().getStringExtra("exception");
    Log.e("HIJACKER/SendLog", stackTrace);

    pref = PreferenceManager.getDefaultSharedPreferences(SendLogActivity.this);
    pref_edit = pref.edit();
    userEmailView.setText(pref.getString("user_email", ""));

    //Load device info
    PackageManager manager = getPackageManager();
    PackageInfo info;
    try {
        info = manager.getPackageInfo(getPackageName(), 0);
        versionName = info.versionName.replace(" ", "_");
        versionCode = info.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        Log.e("HIJACKER/SendLog", e.toString());
    }
    deviceModel = Build.MODEL;
    if (!deviceModel.startsWith(Build.MANUFACTURER))
        deviceModel = Build.MANUFACTURER + " " + deviceModel;
    deviceModel = deviceModel.replace(" ", "_");

    deviceID = pref.getLong("deviceID", -1);

    new SetupTask().execute();
}

From source file:eu.faircode.netguard.SinkholeService.java

private ParcelFileDescriptor startVPN() {
    Log.i(TAG, "Starting");

    // Check state
    boolean metered = Util.isMetered(this);
    boolean wifi = Util.isWifiActive(this);
    boolean roaming = Util.isRoaming(this);
    boolean interactive = Util.isInteractive(this);
    Log.i(TAG, "metered=" + metered + " wifi=" + wifi + " roaming=" + roaming + " interactive=" + interactive);

    // Build VPN service
    final Builder builder = new Builder();
    builder.setSession(getString(R.string.app_name));
    builder.addAddress("10.1.10.1", 32);
    builder.addAddress("fd00:1:fd00:1:fd00:1:fd00:1", 64);
    builder.addRoute("0.0.0.0", 0);
    builder.addRoute("0:0:0:0:0:0:0:0", 0);

    // Add list of allowed applications
    for (Rule rule : Rule.getRules(true, TAG, this)) {
        boolean blocked = (metered ? rule.other_blocked : rule.wifi_blocked);
        if ((!blocked || (rule.unused && interactive)) && (!metered || !(rule.roaming && roaming))) {
            if (debug)
                Log.i(TAG, "Allowing " + rule.info.packageName);
            try {
                builder.addDisallowedApplication(rule.info.packageName);
            } catch (PackageManager.NameNotFoundException ex) {
                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            }/*from   ww w  .j a  va2s. c o m*/
        }
    }

    // Build configure intent
    Intent configure = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, configure, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setConfigureIntent(pi);

    if (debug)
        builder.setBlocking(true);

    // Start VPN service
    try {
        return builder.establish();

    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));

        // Disable firewall
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        prefs.edit().putBoolean("enabled", false).apply();

        // Feedback
        Util.toast(ex.toString(), Toast.LENGTH_LONG, this);
        Widget.updateWidgets(this);

        return null;
    }
}

From source file:net.mypapit.mobile.callsignview.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;//w  w w. jav  a 2s  . c om

    switch (item.getItemId()) {

    case R.id.action_filter:

        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);

        dialogBuilder.setTitle("Search by");
        dialogBuilder.setSingleChoiceItems(new String[] { "Callsign", "Handle" }, -1,
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SharedPreferences.Editor editor = getApplicationContext()
                                .getSharedPreferences("prefs", Context.MODE_PRIVATE).edit();

                        switch (which) {
                        case 0:
                            mSearchHandle = false;
                            searchView.setQueryHint("Search Callsign");
                            showToast("Search by Callsign");
                            editor.putBoolean("mSearchHandle", mSearchHandle);
                            editor.apply();

                            break;

                        case 1:
                            mSearchHandle = true;
                            searchView.setQueryHint("Search Handle/Name");
                            showToast("Search by Handle/Name ");
                            editor.putBoolean("mSearchHandle", mSearchHandle);
                            editor.apply();
                            break;
                        }
                    }
                });

        dialogBuilder.show();
        return true;

    case R.id.showMap:
        intent = new Intent(getApplicationContext(), MapsActivity.class);
        startActivity(intent);
        break;

    case R.id.showFavorites:
        intent = new Intent(this, FavoriteActivity.class);
        startActivity(intent);
        break;

    case R.id.showStats:
        intent = new Intent(this, StatsActivity.class);
        startActivity(intent);
        break;

    case R.id.showAbout:
        try {
            showDialog();
        } catch (PackageManager.NameNotFoundException ex) {
            Snackbar.with(this).text(ex.toString()).show(this);
        }

        break;

    }

    return false;
}

From source file:info.guardianproject.pixelknot.PixelKnotActivity.java

@Override
public List<TrustedShareActivity> getTrustedShareActivities() {
    if (trusted_share_activities == null) {
        trusted_share_activities = new Vector<TrustedShareActivity>();

        Intent intent = new Intent(Intent.ACTION_SEND).setType("image/jpeg");

        PackageManager pm = getPackageManager();
        for (ResolveInfo ri : pm.queryIntentActivities(intent, 0)) {
            if (Arrays.asList(Image.TRUSTED_SHARE_ACTIVITIES)
                    .contains(Image.Activities.get(ri.activityInfo.packageName))) {
                try {
                    ApplicationInfo ai = pm.getApplicationInfo(ri.activityInfo.packageName, 0);
                    TrustedShareActivity tsa = new TrustedShareActivity(
                            Image.Activities.get(ri.activityInfo.packageName), ri.activityInfo.packageName);

                    tsa.setIcon(pm.getApplicationIcon(ai));
                    tsa.createView();//  w w w . j av a 2 s.c o  m
                    tsa.setIntent();

                    trusted_share_activities.add(tsa);

                } catch (PackageManager.NameNotFoundException e) {
                    Log.e(Logger.UI, e.toString());
                    e.printStackTrace();
                    continue;
                }
            }
        }
    }

    return trusted_share_activities;
}

From source file:com.juce.JuceAppActivity.java

public boolean isPermissionDeclaredInManifest (int permissionID)
{
    String permissionToCheck = getAndroidPermissionName(permissionID);

    try// w w  w . ja  va 2  s.co m
    {
        PackageInfo info = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(), PackageManager.GET_PERMISSIONS);

        if (info.requestedPermissions != null)
            for (String permission : info.requestedPermissions)
                if (permission.equals (permissionToCheck))
                    return true;
    }
    catch (PackageManager.NameNotFoundException e)
    {
        Log.d ("JUCE", "isPermissionDeclaredInManifest: PackageManager.NameNotFoundException = " + e.toString());
    }

    Log.d ("JUCE", "isPermissionDeclaredInManifest: could not find requested permission " + permissionToCheck);
    return false;
}

From source file:huajiteam.zhuhaibus.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from   w  w w .  j  a  va 2 s  .  c o  m*/
public boolean onNavigationItemSelected(MenuItem item) {
    int id = item.getItemId();

    Intent intent;
    AlertDialog.Builder dialogBuilder;

    switch (id) {
    case R.id.nav_search:
        intent = new Intent(this, SearchActivity.class);
        startActivity(intent);
        break;
    case R.id.nav_favorite:
        intent = new Intent(this, FavoriteActivity.class);
        startActivity(intent);
        break;
    case R.id.nav_settings:
        intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
        break;
    case R.id.nav_line_listener:
        intent = new Intent(this, LineListenerActivity.class);
        startActivity(intent);
        break;
    case R.id.nav_ckeck_updates:
        this.progressDialog = ProgressDialog.show(this, getString(R.string.check_title),
                getString(R.string.checking));
        new Thread(new Runnable() {
            @Override
            public void run() {
                String nowVer;
                try {
                    nowVer = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
                } catch (PackageManager.NameNotFoundException e) {
                    mHandler.obtainMessage(-2001).sendToTarget();
                    return;
                }
                Response response;
                String latestVer;
                String updateUrl;
                if (nowVer.contains("beta")) {
                    updateUrl = "https://lab.yhtng.com/ZhuhaiBus/updates/beta.json";
                } else {
                    updateUrl = "https://lab.yhtng.com/ZhuhaiBus/updates/stable.json";
                }
                try {
                    response = new GetWebContent().httpGet(updateUrl);
                    latestVer = response.body().string();
                } catch (UnknownHostException | SocketTimeoutException | ConnectException e) {
                    mHandler.obtainMessage(-2003).sendToTarget();
                    return;
                } catch (IOException e) {
                    if (e.toString().contains("okhttp3.Address@")) {
                        mHandler.obtainMessage(-2003).sendToTarget();
                    } else {
                        mHandler.obtainMessage(-2, e.toString()).sendToTarget();
                    }
                    return;
                }
                if (response.code() != 200) {
                    mHandler.obtainMessage(-2002).sendToTarget();
                    return;
                }
                UpdatesData updatesData;
                try {
                    updatesData = new Gson().fromJson(latestVer, UpdatesData.class);
                } catch (StringIndexOutOfBoundsException | JsonSyntaxException | IllegalArgumentException e) {
                    mHandler.obtainMessage(-2002).sendToTarget();
                    return;
                }
                if (updatesData.version.equals(nowVer)) {
                    mHandler.obtainMessage(2000).sendToTarget();
                } else {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("uri", updatesData.downloadURL);
                    map.put("now", nowVer);
                    map.put("new", updatesData.version);
                    map.put("note", updatesData.note);
                    mHandler.obtainMessage(2, map).sendToTarget();
                }
            }

            class UpdatesData {
                String version;
                String downloadURL;
                String note;
            }
        }).start();
        break;
    case R.id.nav_feedback:
        dialogBuilder = new AlertDialog.Builder(MainActivity.this);
        dialogBuilder.setTitle(getString(R.string.title_activity_feed_back));
        dialogBuilder.setMessage(getString(R.string.open_the_link) + "\n"
                + "https://github.com/HuaJiTeam/ZhBus \n" + getString(R.string.to_issue));
        dialogBuilder.setPositiveButton("Open", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/HuaJiTeam/ZhBus")));
            }
        });
        dialogBuilder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dialogBuilder.create().show();
        break;
    case R.id.nav_about:
        dialogBuilder = new AlertDialog.Builder(MainActivity.this);
        dialogBuilder.setTitle("About");
        dialogBuilder.setMessage("HuaJiTeam: https://github.com/HuaJiTeam");
        dialogBuilder.setPositiveButton(getString(R.string.open_source_license),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        makeAlert(getString(R.string.open_source_license),
                                new OpenSourceLicense().getLicense());
                    }
                });
        dialogBuilder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        dialogBuilder.create().show();
        break;
    }
    intent = null;
    dialogBuilder = null;

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

From source file:com.juce.jucedemo.JuceDemo.java

public boolean isPermissionDeclaredInManifest(int permissionID) {
    String permissionToCheck = getAndroidPermissionName(permissionID);

    try {//from ww w . j a v  a2 s  . c om
        PackageInfo info = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(),
                PackageManager.GET_PERMISSIONS);

        if (info.requestedPermissions != null)
            for (String permission : info.requestedPermissions)
                if (permission.equals(permissionToCheck))
                    return true;
    } catch (PackageManager.NameNotFoundException e) {
        Log.d("JUCE", "isPermissionDeclaredInManifest: PackageManager.NameNotFoundException = " + e.toString());
    }

    Log.d("JUCE", "isPermissionDeclaredInManifest: could not find requested permission " + permissionToCheck);
    return false;
}

From source file:eu.faircode.netguard.ServiceSinkhole.java

public void notifyNewApplication(int uid) {
    if (uid < 0)
        return;//from  ww w  .  j av a2  s . c  om

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    try {
        // Get application name
        String name = TextUtils.join(", ", Util.getApplicationNames(uid, this));

        // Get application info
        PackageManager pm = getPackageManager();
        String[] packages = pm.getPackagesForUid(uid);
        if (packages == null || packages.length < 1)
            throw new PackageManager.NameNotFoundException(Integer.toString(uid));
        boolean internet = Util.hasInternet(uid, this);

        // Build notification
        Intent main = new Intent(this, ActivityMain.class);
        main.putExtra(ActivityMain.EXTRA_REFRESH, true);
        main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid));
        PendingIntent pi = PendingIntent.getActivity(this, uid, main, PendingIntent.FLAG_UPDATE_CURRENT);

        TypedValue tv = new TypedValue();
        getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_security_white_24dp).setContentIntent(pi).setColor(tv.data)
                .setAutoCancel(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            builder.setContentTitle(name).setContentText(getString(R.string.msg_installed_n));
        else
            builder.setContentTitle(getString(R.string.app_name))
                    .setContentText(getString(R.string.msg_installed, name));

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);

        // Get defaults
        SharedPreferences prefs_wifi = getSharedPreferences("wifi", Context.MODE_PRIVATE);
        SharedPreferences prefs_other = getSharedPreferences("other", Context.MODE_PRIVATE);
        boolean wifi = prefs_wifi.getBoolean(packages[0], prefs.getBoolean("whitelist_wifi", true));
        boolean other = prefs_other.getBoolean(packages[0], prefs.getBoolean("whitelist_other", true));

        // Build Wi-Fi action
        Intent riWifi = new Intent(this, ServiceSinkhole.class);
        riWifi.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riWifi.putExtra(ServiceSinkhole.EXTRA_NETWORK, "wifi");
        riWifi.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi);

        PendingIntent piWifi = PendingIntent.getService(this, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action wAction = new NotificationCompat.Action.Builder(
                wifi ? R.drawable.wifi_on : R.drawable.wifi_off,
                getString(wifi ? R.string.title_allow_wifi : R.string.title_block_wifi), piWifi).build();
        builder.addAction(wAction);

        // Build mobile action
        Intent riOther = new Intent(this, ServiceSinkhole.class);
        riOther.putExtra(ServiceSinkhole.EXTRA_COMMAND, ServiceSinkhole.Command.set);
        riOther.putExtra(ServiceSinkhole.EXTRA_NETWORK, "other");
        riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid);
        riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]);
        riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other);
        PendingIntent piOther = PendingIntent.getService(this, uid + 10000, riOther,
                PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Action oAction = new NotificationCompat.Action.Builder(
                other ? R.drawable.other_on : R.drawable.other_off,
                getString(other ? R.string.title_allow_other : R.string.title_block_other), piOther).build();
        builder.addAction(oAction);

        // Show notification
        if (internet)
            NotificationManagerCompat.from(this).notify(uid, builder.build());
        else {
            NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                expanded.bigText(getString(R.string.msg_installed_n));
            else
                expanded.bigText(getString(R.string.msg_installed, name));
            expanded.setSummaryText(getString(R.string.title_internet));
            NotificationManagerCompat.from(this).notify(uid, expanded.build());
        }

    } catch (PackageManager.NameNotFoundException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }
}