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\"/>");
}
}
}
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;
}
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);
}
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();
}
}
});
}
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;
}
Aggregations