Example usage for android.content Intent setAction

List of usage examples for android.content Intent setAction

Introduction

In this page you can find the example usage for android.content Intent setAction.

Prototype

public @NonNull Intent setAction(@Nullable String action) 

Source Link

Document

Set the general action to be performed.

Usage

From source file:piramide.multimodal.client.tester.ApplicationDownloader.java

void install() {
    final Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(//from   w w w  .  j  a  v a2s  .c  o  m
            Uri.parse("file://" + this.activity.getFilesDir().getAbsolutePath() + "/" + APK_FILENAME),
            "application/vnd.android.package-archive");
    this.activity.startActivity(intent);
}

From source file:piramide.multimodal.downloader.client.ApplicationDownloader.java

void install() {
    final Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(//from  ww  w . j  a va2s. co  m
            Uri.parse("file://" + this.context.getFilesDir().getAbsolutePath() + "/" + APK_FILENAME),
            "application/vnd.android.package-archive");
    this.context.startActivity(intent);
}

From source file:com.manning.androidhacks.hack046.ReplyActivity.java

public void onSendClick(View v) {
    String msg = mEditText.getText().toString();

    if (TextUtils.isEmpty(msg)) {
        Toast.makeText(this, "Empty msg!", Toast.LENGTH_SHORT).show();
        return;/*from   w w  w  .j  a va 2s.  c om*/
    }

    Intent intent = new Intent(this, MsgService.class);
    intent.setAction(MsgService.MSG_REPLY);
    intent.putExtra(MsgService.MSG_REPLY_KEY, msg);
    startService(intent);

    finish();
}

From source file:ac.robinson.bettertogether.api.messaging.PluginConnectionDelegate.java

@SuppressFBWarnings("ANDROID_BROADCAST")
public void sendMessage(@NonNull BroadcastMessage message) {
    Intent intent = new Intent();
    intent.setAction(PluginIntent.ACTION_MESSAGE_RECEIVED);
    intent.setClassName(PluginIntent.HOST_PACKAGE, PluginIntent.MESSAGE_RECEIVER);
    intent.putExtra(PluginIntent.KEY_BROADCAST_MESSAGE, message);

    // note: source is only necessary for internal plugins - it may be removed at a later date
    intent.putExtra(PluginIntent.EXTRA_SOURCE, PluginMessageCallback.class.getPackage().toString());

    mContext.sendBroadcast(intent);//from  w w  w .  j a  v  a 2  s .  co m
}

From source file:com.zzl.zl_app.cache.Utility.java

public static boolean loadFile(String loadpath, String fileName, String savePath, Context context,
        String broadcastAction) {
    FileOutputStream fos = null; // ?
    FileInputStream fis = null; // ?
    InputStream is = null; // ?
    HttpURLConnection httpConnection = null;
    int readLength = 0; // ??
    int file_length = 0;
    URL url = null;//from  w ww.j  a  v a 2  s  .c o  m
    try {
        url = new URL(loadpath);
        httpConnection = (HttpURLConnection) url.openConnection();
        httpConnection.setConnectTimeout(10000);
        httpConnection.setRequestMethod("GET");
        is = httpConnection.getInputStream();
        FileTools.creatDir(savePath);
        String filePath = savePath + fileName;
        FileTools.deleteFile(filePath);
        FileTools.creatFile(filePath);
        File download_file = new File(filePath);
        fos = new FileOutputStream(download_file, true); // ??
        fis = new FileInputStream(download_file); // ??
        int total_read = fis.available(); // ??0
        file_length = httpConnection.getContentLength(); // ?
        if (is == null) { // ?
            Tools.log("Voice", "donload failed...");
            return false;
        }
        byte buf[] = new byte[3072]; // 
        readLength = 0; // 
        Tools.log("Voice", "download start...");
        Intent startIntent = new Intent();
        Bundle b = new Bundle();
        if (broadcastAction != null) {
            // ?????
            b.putInt("fileSize", file_length);
            b.putInt("progress", 0);
            startIntent.putExtras(b);
            startIntent.setAction(broadcastAction);
            context.sendBroadcast(startIntent);
        }
        // ?????
        while (readLength != -1) {
            if ((readLength = is.read(buf)) > 0) {
                fos.write(buf, 0, readLength);
                total_read += readLength; // 
            }
            if (broadcastAction != null) {
                b.putInt("fileSize", file_length);
                b.putInt("progress", total_read);
                startIntent.putExtras(b);
                startIntent.setAction(broadcastAction);
                context.sendBroadcast(startIntent);
            }
            if (total_read == file_length) { // ?
                Tools.log("Voice", "download complete...");
                // ??????
                if (broadcastAction != null) {
                    Intent completeIntent = new Intent();
                    b.putBoolean("isFinish", true);
                    completeIntent.putExtras(b);
                    completeIntent.setAction(broadcastAction);
                    context.sendBroadcast(completeIntent);
                }

            }
            // Thread.sleep(10); // ?10
        }
    } catch (Exception e) {
        if (broadcastAction != null) {
            Intent errorIntent = new Intent();
            errorIntent.setAction(broadcastAction);
            context.sendBroadcast(errorIntent);
            e.printStackTrace();
        }
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
            if (fis != null) {
                is.close();
            }
            if (fis != null) {
                fis.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return true;
}

From source file:com.nadmm.airports.aeronav.AeroNavService.java

protected void sendResult(String action, Bundle extras) {
    Intent result = new Intent();
    result.setAction(action);/*from   ww  w.  j  a  v  a 2  s  . co m*/
    result.putExtras(extras);
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(this);
    bm.sendBroadcast(result);
}

From source file:com.manning.androidhacks.hack004.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.prefs);

    Preference sharePref = findPreference("pref_share");
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Check this app!");
    shareIntent.putExtra(Intent.EXTRA_TEXT, "Check this awesome app at: ...");
    sharePref.setIntent(shareIntent);/*from w  w  w. j av  a  2 s . c o m*/

    Preference ratePref = findPreference("pref_rate");
    Uri uri = Uri.parse("market://details?id=" + getPackageName());
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    ratePref.setIntent(goToMarket);

    updateUserText();
}

From source file:MainActivity.java

private void showNotification() {
    Intent activityIntent = new Intent(this, MainActivity.class);
    activityIntent.setAction(ACTION_STOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, activityIntent, 0);
    final Builder notificationBuilder = new Builder(this).setContentTitle("Flashlight")
            .setContentText("Press to turn off the flashlight").setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setContentIntent(pendingIntent).setVibrate(new long[] { DEFAULT_VIBRATE })
            .setPriority(PRIORITY_MAX);/*from   w  ww. jav  a 2s  . c  o  m*/
    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    try {/*from w w  w .j a  v  a2s  . c  o m*/
        String packageName = obj.getString(PACKAGE_NAME);
        String feedName = obj.getString("sharedFeedName");
        JSONArray ids = obj.getJSONArray(PARTICIPANTS);
        Intent launch = new Intent();
        launch.setAction(Intent.ACTION_MAIN);
        launch.addCategory(Intent.CATEGORY_LAUNCHER);
        launch.putExtra("type", "invite_app_feed");
        launch.putExtra("creator", false);
        launch.putExtra("sender", from.id);
        launch.putExtra("sharedFeedName", feedName);
        launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        long[] idArray = new long[ids.length()];
        for (int i = 0; i < ids.length(); i++) {
            idArray[i] = ids.getLong(i);
        }
        launch.putExtra("participants", idArray);
        launch.setPackage(packageName);
        final PackageManager mgr = context.getPackageManager();
        List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0);
        if (resolved.size() == 0) {
            Toast.makeText(context, "Could not find application to handle invite.", Toast.LENGTH_SHORT).show();
            return;
        }
        ActivityInfo info = resolved.get(0).activityInfo;
        launch.setComponent(new ComponentName(info.packageName, info.name));
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
                PendingIntent.FLAG_CANCEL_CURRENT);

        (new PresenceAwareNotify(context)).notify("New Invitation from " + from.name,
                "Invitation received from " + from.name, "Click to launch application: " + packageName,
                contentIntent);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }
}

From source file:com.allwinner.theatreplayer.launcher.service.UpdateService.java

private void sendPost(String server_url) {
    //      Log.v(TAG, "send post to server");
    HttpPost post = new HttpPost(server_url);
    List<NameValuePair> params = new ArrayList<NameValuePair>();

    params.add(new BasicNameValuePair("guid", "646212C46B774f95BBBE2F9CCFF32797"));
    params.add(new BasicNameValuePair("service_type", "APK_UPDATE"));
    params.add(new BasicNameValuePair("para_serial", Utils.rcId));

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setSoTimeout(httpParameters, Utils.CHECK_TIMEOUT);
    HttpClient httpClient = new DefaultHttpClient(httpParameters);
    try {//  w w  w . ja va2 s .c  o  m
        post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        HttpResponse response = httpClient.execute(post);
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            String data = EntityUtils.toString(entity, "UTF-8");
            Utils.saveUpdateJson(data, Utils.sdcardPathQQ + "/update.json");
            JSONObject jsonobj = new JSONObject(data);
            int version = jsonobj.getInt("version");
            //            Log.i(TAG, "?md5 = "+jsonobj.getString("md5"));
            //            Log.i(TAG, "version = "+version);
            //            Log.i(TAG, "local  = "+Utils.getVersionCode(this));         
            //            Log.i(TAG, "url  = "+jsonobj.getString("url"));         
            if (version > Utils.getVersionCode(this)) {
                // 
                Intent intent = new Intent();
                intent.setAction(APKONCHECKED);
                sendBroadcast(intent);
            }
        } else {
            Log.i(TAG, "1: response status:  " + response.getStatusLine().getStatusCode());

        }
    } catch (Exception e) {
        Log.i(TAG, "Exception ERROR_UNKNOWN" + e.getMessage());
    }
}