Search in sources :

Example 16 with Intent

use of android.content.Intent in project Android-Error-Reporter by tomquist.

the class ExceptionReporter method reportException.

private void reportException(Thread thread, Throwable ex, String extraMessage, boolean manual) {
    final Writer writer = new StringWriter();
    final PrintWriter pWriter = new PrintWriter(writer);
    ex.printStackTrace(pWriter);
    String stackTrace = writer.toString();
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
    Intent intent = new Intent();
    // Makes the intent unique 
    intent.setData((Uri.parse("custom://" + SystemClock.elapsedRealtime())));
    intent.setAction(ExceptionReportService.ACTION_SEND_REPORT);
    intent.putExtra(ExceptionReportService.EXTRA_THREAD_NAME, thread.getName());
    intent.putExtra(ExceptionReportService.EXTRA_EXCEPTION_CLASS, ex.getClass().getName());
    intent.putExtra(ExceptionReportService.EXTRA_EXCEPTION_TIME, format.format(new Date()));
    intent.putExtra(ExceptionReportService.EXTRA_STACK_TRACE, stackTrace);
    intent.putExtra(ExceptionReportService.EXTRA_MESSAGE, ex.getMessage());
    intent.putExtra(ExceptionReportService.EXTRA_MANUAL_REPORT, manual);
    intent.putExtra(ExceptionReportService.EXTRA_AVAILABLE_MEMORY, getAvailableInternalMemorySize());
    intent.putExtra(ExceptionReportService.EXTRA_TOTAL_MEMORY, getTotalInternalMemorySize());
    if (extraMessage != null)
        intent.putExtra(ExceptionReportService.EXTRA_EXTRA_MESSAGE, extraMessage);
    intent.setClass(context, ExceptionReportActivity.class);
    List<ResolveInfo> resolvedActivities = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (!resolvedActivities.isEmpty()) {
        Log.v(TAG, ExceptionReportActivity.class.getSimpleName() + " is registered. Generating notification...");
        Notification notification = new Notification();
        notification.icon = getNotificationIcon();
        notification.tickerText = getNotificationTickerText();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, getNotificationTitle(), getNotificationMessage(), PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify(new Random().nextInt(), notification);
    } else {
        intent.setClass(context, ExceptionReportService.class);
        ComponentName service = context.startService(intent);
        if (service == null) {
            Log.e(TAG, "Service has not be added to your AndroidManifest.xml\n" + "Add the following line to your manifest:\n" + "<service android:name=\"" + ExceptionReportService.class.getName() + "\" android:process=\":exceptionReporter\"/>");
        }
    }
}
Also used : NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Date(java.util.Date) Notification(android.app.Notification) ResolveInfo(android.content.pm.ResolveInfo) StringWriter(java.io.StringWriter) Random(java.util.Random) ComponentName(android.content.ComponentName) SimpleDateFormat(java.text.SimpleDateFormat) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 17 with Intent

use of android.content.Intent in project coursera-android by aporter.

the class DialtactsActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.dialtacts_options, menu);
    // set up intents and onClick listeners
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar);
    final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
    final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact);
    callSettingsMenuItem.setIntent(DialtactsActivity.getCallSettingsIntent());
    searchMenuItem.setOnMenuItemClickListener(mSearchMenuItemClickListener);
    filterOptionMenuItem.setOnMenuItemClickListener(mFilterOptionsMenuItemClickListener);
    addContactOptionMenuItem.setIntent(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
    return true;
}
Also used : MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) Intent(android.content.Intent)

Example 18 with Intent

use of android.content.Intent in project coursera-android by aporter.

the class DataTransferActivity method selectServer.

private void selectServer() {
    setButtonsEnabled(false);
    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    ArrayList<String> pairedDeviceStrings = new ArrayList<String>();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            pairedDeviceStrings.add(device.getName() + "\n" + device.getAddress());
        }
    }
    Intent showDevicesIntent = new Intent(this, ShowDevices.class);
    showDevicesIntent.putStringArrayListExtra("devices", pairedDeviceStrings);
    startActivityForResult(showDevicesIntent, SELECT_SERVER);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Example 19 with Intent

use of android.content.Intent in project coursera-android by aporter.

the class ShowDevices method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    final ListView lv = getListView();
    final TextView footer = new TextView(this);
    footer.setText("Discover More Devices");
    lv.setFooterDividersEnabled(true);
    lv.addFooterView(footer, null, true);
    final List<String> devices = getIntent().getStringArrayListExtra("devices");
    mArrayAdapter = new ArrayAdapter<String>(this, R.layout.list_item, devices);
    setListAdapter(mArrayAdapter);
    getListView().setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
            if (parent.getAdapter().getItemViewType(pos) == AdapterView.ITEM_VIEW_TYPE_HEADER_OR_FOOTER) {
                mBluetoothAdapter.startDiscovery();
            } else {
                String tmp = (String) parent.getItemAtPosition(pos);
                BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(tmp.split("\n")[1]);
                Intent data = new Intent();
                data.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
                setResult(RESULT_OK, data);
                finish();
            }
        }
    });
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) BluetoothDevice(android.bluetooth.BluetoothDevice) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) TextView(android.widget.TextView)

Example 20 with Intent

use of android.content.Intent in project coursera-android by aporter.

the class CheckActivityIntents method getActivitiesForAction.

public static List<String> getActivitiesForAction(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action.trim());
    final List<ResolveInfo> list = packageManager.queryIntentActivities(intent, 0);
    final List<String> acts = new ArrayList<String>();
    for (ResolveInfo ri : list) {
        acts.add(ri.activityInfo.name);
    }
    return acts;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Aggregations

Intent (android.content.Intent)14391 PendingIntent (android.app.PendingIntent)2805 View (android.view.View)1068 ComponentName (android.content.ComponentName)965 Bundle (android.os.Bundle)888 Uri (android.net.Uri)762 ResolveInfo (android.content.pm.ResolveInfo)757 Context (android.content.Context)686 TextView (android.widget.TextView)669 RemoteException (android.os.RemoteException)657 Test (org.junit.Test)590 PackageManager (android.content.pm.PackageManager)553 IntentFilter (android.content.IntentFilter)519 ArrayList (java.util.ArrayList)486 ActivityNotFoundException (android.content.ActivityNotFoundException)398 ImageView (android.widget.ImageView)395 File (java.io.File)364 IOException (java.io.IOException)361 BroadcastReceiver (android.content.BroadcastReceiver)360 Notification (android.app.Notification)302